Document directory
- If the declared class member or method is static, you can directly access the static member without instantiating the class. You cannot access the static member through an object (except for static methods, the method can be ). Static members belong to the class and do not belong to any object instance, but the object instances of the class can be shared.
If the declared class member or method is static, you can directly access the static member without instantiating the class. You cannot access the static member through an object (except for static methods, the method can be ). Static members belong to the class and do not belong to any object instance, but the object instances of the class can be shared. <? PHP
Class person {
// Define static member attributes
Public static $ Country = "China ";
// Define the static member Method
Public static function mycountry (){
// Static member attributes for internal access
Echo "I am". SELF: $ country. "person <br/> ";
}
}
Class student extends person {
Function Study (){
Echo "I am". Parent: $ country. "person <br/> ";
}
}
// Output the member property value
Echo person: $ country. "<br/>"; // output: China
$ P1 = new person ();
// Echo $ P1-> country; // incorrect syntax
// Method for accessing static members
Person: mycountry (); // output: I am a Chinese
// Static methods can also be accessed through objects:
$ P1-> mycountry (); // The member attribute value is output in the subclass.
Echo Student: $ country. "<br/>"; // output: China
$ T1 = new student ();
$ T1-> Study (); // output: I am a Chinese
?>