Php_get () _ set () _ construct ()

Source: Internet
Author: User
Php _ get () _ set () _ construct () function _ construct ($ name, $ sex, $ age, $ school )?????? {????????? $ This-& gt; name $ name ;????????? $ This-& gt; sex $ sex ;????????? $ This-& g php _ get () _ set () _ construct ()

Function _ construct ($ name, $ sex, $ age, $ school)

??? ??? {

??? ??? ??? $ This-> name = $ name;

??? ??? ??? $ This-> sex = $ sex;

??? ??? ??? $ This-> age = $ age;

??? ??? ??? $ This-> school = $ school;

}

?

?

?

Function _ get ($ property_name)
?? {?
??? // Echo "the _ get () method is automatically called when the private property value is directly obtained.
";
???? If (isset ($ this-> $ property_name )){
???? Return ($ this-> $ property_name );
??? } Else {
???? Return (NULL );
???}
??}

?? // _ Set () is used to set private attributes.
?? Function _ set ($ property_name, $ value)
?? {
?? //? Echo "when the private property value is directly set, the _ set () method is automatically called to assign values to the private property.
";
??? $ This-> $ property_name = $ value;
??} ?

?

?

Function setAge ($ age )? // Provide a public age setting method for external users

??? {

??? ??? If ($ age <0 | $ age> 130) // when assigning a value to an attribute, to avoid setting an invalid value to the attribute

??? ??? ??? Return;

??? ??? $ This-> age = $ age;

}

Function getAge ()??? // Provide a public method for obtaining the age.

{

??? Return ($ this-> age );

}

?

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.