What is the static state after PHP5.3? There are instance code, not the title party

Source: Internet
Author: User
1: Success {code...} 2: Failure {code...} I want to know how to understand static correctly and how to use static appropriately? 1: Successful


  

2: Failed


   

I want to know how to understand static correctly and how to use static appropriately?

Reply content:

1: Successful


    

2: Failed


     

I want to know how to understand static correctly and how to use static appropriately?

After PHP 5.3Delayed binding. Http://www.php-internals.com/book? P = chapt05/05-05-class-magic-methods-latebinding

In earlier versions, if you run the following code:


      

$ Foo gets a Domain object instead of a Document Object. This is because a problem exists in the previous PHP version, that is, the parent class cannot obtain the subclass State, resulting in inheritance.selfThis value points to the parent class rather than the Child class. To implement normal functions, you must rewrite the method in the subclass.

Later, in PHP 5.3staticTo achieve delayed binding, you only need to usestaticTo replaceselfKeyword.

It is easy to understand that self is the parent class of the current class or the current class. In this example, it is definitely wrong to instantiate an abstract class. The official explanation of static is the meaning of static late binding, and the popular point is a sub-class. In this case, the landlord's example will surely be accessible.

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.