New features of php53: delayed static binding

Source: Internet
Author: User
: This article mainly introduces the latency static binding of new features of php53. For more information about PHP tutorials, see. PHP-based version: 5.3.5

After PHP5.3, delayed static binding is introduced:

Static (keyword) is similar to self, but it points to the called class (Document) instead of the containing class (DomainObject), the difference between static and self:

The main function is to make up for the original shortcomings. the original child class can use parent to find the parent class object. now, the child class can use static to find the child class object that inherits it.

class A  {      public static function echoClass()      {          echo __CLASS__;      }  
    public function what(){ echo __CLASS__;}
Public static function test (){
$ This-> what (); // output B
Static: echoClass (); // output B self: echoClass (); // output A} class B extends A {public static function echoClass () {echo _ CLASS __;}} B: test ();

Self is the object of the current class, static is the object of the called class, $ this is the object of the currently called class, but $ this cannot call static attributes, self can, _ CLASS _ is used to specify the name of a CLASS. it is generally used to register a CLASS.

class B extends A  {            public static function echoClass($name=1)      {      spl_autoload_register(array(__CLASS__,"echoClass"));         echo __CLASS__;      }  }  

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the new features of php53, including the delayed static binding, and hopes to be helpful to friends who are interested in PHP tutorials.

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.