您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php 静态绑定之static::

2024/3/28 9:39:50发布20次查看
对于静态绑定中的static::在此不多做解释,我想用实例来证明,这个例子是来自官方文档:
for example one: class a{ private function foo(){ echo this is a test function.
; } public function test(){ $this->foo(); static::foo(); }}$a=new a();$a->test();
输出结果:
this is a test function
this is a test function
for example two: class a{ private function foo(){ echo this is a test function.
; } public function test(){ $this->foo(); static::foo(); }}class b extends a{}$b=new b();$b->test();
输出结果:
this is a test function
this is a test function
for example three: class a{ private function foo(){ echo this is a test function.
; } public function test(){ $this->foo(); static::foo(); }}class b extends a{}class c extends a{ private function foo(){ } } $c=new c();$c->test();
输出结果:
this is a test function
( ! ) fatal error: call to private method c::foo() from context ‘a’ in d:\www\testxdebug\index.php on line 21
call stack
time memory function location
1 0.0156 135536 {main}( ) …\index.php:0
2 0.0156 135936 a->test( ) …\index.php:35
版权声明:本文为博主原创文章,未经博主允许不得转载。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product