Home  >  Article  >  Backend Development  >  PHP53 new feature delayed static binding

PHP53 new feature delayed static binding

WBOY
WBOYOriginal
2016-08-08 09:19:34932browse
Based on PHP version: 5.3.5PHP5.3 later introduced delayed static binding: static(keyword) is similar to self(keyword), but it points to being called The difference between , static and self : the main function of is to make up for the original shortcomings of the original subclass You can use parent to find the parent class object. Now you can use static in the parent class to find the subclass object that currently inherits it.
class A  
{  
    public static function echoClass()  
    {  
        echo __CLASS__;  
    }  
    public function what(){ echo __CLASS__;}
    public static function test()  
    {  
        <pre name="code" class="php">        $this->what(); //输出B 
static::echoClass(); //Output B self::echoClass(); //Output A } } class B extends A { public static function echoClass() { echo __CLASS__; } } B::test( );
self refers to the object of the current class, 

static refers to the object of the calling class, $this also refers to the object of the currently calling class, but $this cannot To call static attributes, self can be used, and __CLASS__ is used to specify the name of the class, which is generally used to register the class method.

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

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above has introduced the new feature of php53, delayed static binding, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn