What is the role of @ property in php?

Source: Internet
Author: User
What is the role of @ property in php? I found that the following code can also be used in the class after I declare the property with @ property! What is the difference between adminName1 and adminName2? Is it generally stated that all attributes use @ property?

/**
* @ Property string adminName1
*/

Class test {

Private $ adminName2;

Public function getName ($ pram1, $ pram2 ){
$ This-> adminName1 = $ pram1;
$ This-> adminName2 = $ pram2;
}
}

?>


Reply to discussion (solution)

Didn't you see that he was in the comment?

@ Property string adminName1
Indicates that the property adminName1 is a string.

This is just to help understand the instructions of the program

I can see that it is in the comment and can be used for prompt information when calling elsewhere! I don't understand why it can be used in the class?

You can follow the rules. Where is the code from?

I saw it in the yii Framework. However, if I write a test myself, you can:

/**
* @ Property string adminName1
*/

Class test {

Private $ adminName2;

Public function setName ($ pram1, $ pram2 ){
$ This-> adminName1 = $ pram1;
$ This-> adminName2 = $ pram2;
}

Public function getName (){
Return $ result = $ this-> adminName1. ". $ this-> adminName2;
}
}
$ Test = new test ();
$ Test-> setName ("admin1", "admin2 ");
Echo $ test-> getName ();
?>
// Output result: admin1 admin2

So I wonder if php has this rule?

I have already said it is to help understand the instructions of the program.
Change like you
/**
* @ Property string adminName1
*/
There is no meaning to explain. On the contrary, there will be misunderstandings.
Clearly, he said there was an adminName1 attribute. Why didn't I see it? Only adminName2 is displayed. do you want to define an adminName1?

What are you talking about?

I have already said it is to help understand the instructions of the program.
Change like you
/**
* @ Property string adminName1
*/
There is no meaning to explain. On the contrary, there will be misunderstandings.
Clearly, he said there was an adminName1 attribute. Why didn't I see it? Only adminName2 is displayed. do you want to define an adminName1?
Thank you very much for your answer, but I don't think you understand what I mean!

I am also looking for the answer to this question. I did not understand what the author meant by the reply platform.

I personally understand the answer without google. this is for IDE,
@ Property keyword is used as an escape. IDE automatically adds an attribute list to this annotation (even if it does not exist, you can try adding a nonexistent attribute in this format ).

The purpose is to make some magic properties explicit and make the calling developers clearer. of course, IDE support is required.

After the attribute is identified, the attribute is still not defined, and the _ set and _ get methods are finally called for these attributes. Common usage methods are as follows:

public function __get($name){$getter='get'.$name;if(method_exists($this,$getter))return $this->$getter();}

Finally, the methods for these undefined attributes are converted to get/set function access.

I am also looking for the answer to this question. I did not understand what the author meant by the reply platform.

I personally understand the answer without google. this is for IDE,
@ Property keyword is used as an escape. IDE automatically adds an attribute list to this annotation (even if it does not exist, you can try adding a nonexistent attribute in this format ).

The purpose is to make some magic properties explicit and make the calling developers clearer. of course, IDE support is required.

Well, I think what you said makes sense. This type of attribute must be assigned a value before use. if it is not assigned a value, a warning will be given.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.