In this paper, we analyze the memory location of statically static properties and methods in object-oriented PHP. Share to everyone for your reference. Specifically as follows:
The memory location of static statically properties--> classes, not objects. Here's a test to prove
<?php
Header ("Content-type:text/html;charset=utf-8");
Class human{
static public $name = "little sister";
public $height;
Public function tell () {
}
}
echo Human: $name;
Without relying on the object, you can access it directly. Because the memory location of the static property is in the class, not the object.
$p 1 = new Human ();
$p 2 = new Human ();
Print_r ($p 1);
echo $p 1:: $name = "Lady";
Change the value of the static property on the $p1 object, and the $p2 object will change accordingly.
echo $p 2:: $name;
? >
The results of the output can be seen:
1, Echo Human: $name: The class declaration is complete, there is a static property, does not depend on the object. Therefore, there is only one static property (meaning in memory, the location is not in the object, if in the object, that instantiate an object, there is the corresponding 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, the value of the property for all objects will be affected.
For methods, whether static or normal, they exist in the class memory space. Proof is also very simple, new an object, Print_r (object) can be.
I hope this article will help you with your PHP program design.