PHP53 new feature delayed static binding
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( );
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.
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31