The memory location analysis of static properties and methods in object-oriented PHP, Object-oriented static_php tutorial

Source: Internet
Author: User

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.