This paper analyzes the difference between static class and static variable usage class in PHP, creates object $object = new Class () and then invokes with "--" $object->attribute/function, if the variable/method is accessible. Direct invocation of the class method amount: Class::attribute/function, either static/non-static, static: declares that a class member or method is static, can be accessed without instantiating a class, and cannot access static members through an object ( Except for static methods), static members belong to a class and do not belong to any object instance, but object instances of the class can be shared.
First download the class library for static and static variables used in PHP that we need to use in this lesson: http://www.php.cn/xiazai/leiku/610
After the download, find the PHP class files we need, unzip to our local directory, create a new PHP file!
Once this is done, we will invoke this class in the new PHP file, and instantiate the class:
<?phpinclude_once "person.php";//Import class file//Output member property value echo Person:: $country. " <br/> "; Output: China $p1 = new Person ();//echo $p 1->country; Error notation//Access static Member Method Person::mycountry (); Output: I am Chinese//static methods can also be accessed by object: $p 1->mycountry ();//The Output member property value in the Subclass Echo Student:: $country. " <br/> "; Output: China $t1 = new Student (); $t 1->study (); Output: I am a Chinese?>
Run the file and get the results as shown: