PHP late static binding example sharing

小云云
Release: 2023-03-21 10:02:01
Original
1160 people have browsed it

1. The working principle of late static binding is to store the class name in the previous "non-forwarding call" (non-forwarding call). When making a static method call, the class name is the one explicitly specified (usually on the left side of the :: operator); when making a non-static method call, it is the class to which the object belongs. This feature is named "late static binding" from a language-internal perspective. "Late binding" means that static:: is no longer resolved to the class in which the current method is defined, but is calculated at actual runtime.

2. Test example:

class A{    public function run()    
{        static::test(); //后期静态绑定        
self::test(); //不是后期静态绑定    }    
public static function test()    
{        echo &#39;A Class<br>&#39;;    
}}class B extends A
{    public static function test()   
{        echo &#39;B Class<br>&#39;;    }}
$a = new B();$a->run();
//输出结果
//B Class
//A Class
Copy after login

Related recommendations:

Detailed description of a late static binding in Laravel

PHP object-oriented post-static binding function introduction

php post-static binding

The above is the detailed content of PHP late static binding example sharing. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!