The memory location analysis of static properties and methods in object-oriented PHP, object-oriented static
In this paper, we analyze the memory location of static property and method in PHP object-oriented. Share to everyone for your reference. Specific as follows:
Static property of the memory location-class, not the object. Here's a test to prove it.
<?phpheader ("Content-type:text/html;charset=utf-8"), class human{static public $name = "Little Sister", public $height, public function tell () {}}echo Human: $name;//Not dependent on the object, it can be accessed directly. Because the memory location of the static property is in the class, not the object. $p 1 = new Human (), $p 2 = new Human ();p Rint_r ($p 1); Echo $p 1:: $name = "Madame";//change the value of the static property on the $p1 object, and the $p2 object will change accordingly. echo $p 2:: $name;? >
The output can be shown as follows:
1, Echo Human: $name: class declaration is complete, there is a static property, not dependent on the object. Therefore, there is only one static property (meaning that in memory, the location is not in the object; If you instantiate an object in the object, it has the static position, such as the Height property);
2, Print_r ($p 1): Print results only the Height property, and no name;
3. When the value of a static property changes, all objects will be affected by that property value.
For a method, whether static or normal, it exists in the class memory space. The proof is also very simple, new object, Print_r (object) can be.
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/955407.html www.bkjia.com true http://www.bkjia.com/PHPjc/955407.html techarticle the memory location analysis of static properties and methods in object-oriented PHP, object-oriented static This paper analyzes the memory location of static properties and methods in object-oriented PHP. Share to the big ...