Home > Backend Development > PHP Tutorial > PHP53 new feature delayed static binding

PHP53 new feature delayed static binding

WBOY
Release: 2016-08-08 09:19:34
Original
966 people have browsed it
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__;  
    }  
Copy after login
    public function what(){ echo __CLASS__;}
Copy after login
    public static function test()  
    {  
        <pre name="code" class="php">        $this->what(); //输出B 
Copy after login
static::echoClass(); //Output B self::echoClass(); //Output A } } class B extends A { public static function echoClass() { echo __CLASS__; } } B::test( );
Copy after login
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__;  
    }  
}  
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template