My younger brother, I cannot return the name or age here.
Source: Internet
Author: User
I cannot return the name or age here. & lt ;? PhpclassPerson {? Private $ name ;? Private $ sex ;? Private $ age ;??? // Constructor? Function _ construct ($ na what can I do? I cannot return the name or age here
Class Person {
? Private $ name;
? Private $ sex;
? Private $ age;
? ?
? // Constructor
? Function _ construct ($ name = "", $ sex = "male", $ age = 1 ){
? $ This-> name = $ name;
? $ This-> sex = $ sex;
? $ This-> age = $ age;
? }
? ?
? // Add the _ get () method
? Public function _ get ($ propertName ){
? If ($ propertName = "sex "){
? Return "confidential ";
? }
? Else if ($ propertyName = "age ")
? {
? If ($ this-> age> 30)
? Return $ this-> age-10;
? ?
? Else
? Return $ this-> $ propertyName;
? ?
? }
? Else
? {
? Return $ this-> $ propertyName;
? }
? ?
? }
}
$ Person1 = new Person ("zhang san", "male", 20 );
Echo "name:". $ person1-> name ."
";
Echo "gender:". $ person1-> sex ."
";
Echo "age:". $ person1-> age ."
";
?>
I cannot return the name or age here?
The returned result is as follows:
Name:
Gender: Confidential
Age:
? Thank you for your answers!
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