Home > Article > Backend Development > Memory location analysis of static properties and methods in PHP object-oriented_PHP tutorial
This article mainly introduces the memory location of static properties and methods in PHP object-oriented, through the memory location Examples analyze the principles and usage techniques of static properties. Friends in need can refer to it
The example of this article analyzes the memory location of static properties and methods in PHP object-oriented. Share it with everyone for your reference. The details are as follows:
static The memory location of static properties -> class, not object. Let’s do a test to prove it
?
3 4 5 6 7 8 9 10
|
header("content-type:text/html;charset=utf-8");<🎜> <🎜>class Human{<🎜> <🎜>static public $name = "Little Sister";<🎜> <🎜>public $height;<🎜> <🎜>public function tell(){<🎜> <🎜>}<🎜> <🎜>}<🎜> <🎜>echo Human:$name;<🎜> <🎜>//It can be accessed directly without relying on objects. Because the memory location of static properties is in the class, not the object. <🎜> <🎜>$p1 = new Human();<🎜> <🎜>$p2 = new Human();<🎜> <🎜>print_r($p1);<🎜> <🎜>echo $p1::$name = "Mrs.";<🎜> <🎜>//Change the value of the static attribute on the $p1 object, and the $p2 object will also change accordingly. <🎜> <🎜>echo $p2::$name;<🎜> <🎜>?> |