The difference between class static call and scope resolution operator in PHP

小云云
Release: 2023-03-19 12:44:01
Original
1254 people have browsed it

This article mainly introduces the difference between class static calling and range resolution operators in PHP. Friends who need it can refer to it. I hope it can help everyone.

The specific code is as follows:


who(); // 输出 'child' static::who(); // 延迟静态绑定 是范围解析,不是静态调用 } function who() { echo 'parent
'; } } class ChildClass extends ParentClass { public static $my_static = 'child var '; function who() { echo 'child
'; } } $obj = new ChildClass(); $obj->test(); echo ChildClass::$my_static;//静态调用
Copy after login

The above output

parent

child

child

child var

Related recommendations:

Can non-static methods be called statically in PHP? (Weird call)

Application analysis of PHP statically calling non-static methods_PHP tutorial

Application analysis of PHP statically calling non-static methods

The above is the detailed content of The difference between class static call and scope resolution operator in PHP. 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
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!