• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php 静态绑定之static::

php 搞代码 3年前 (2022-01-23) 14次浏览 已收录 0个评论

对于静态绑定中的static::在此不多做解释,我想用实例来证明,这个例子是来自官方文档:

For example one:

class A{   private function foo(){       echo "this is a test function"."<br>";   }   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"."<br>";   }   public function test(){       $this->foo();       static::foo();   }}class B extends A{}$B=new B();$B->test();

输出结果:
this is a test function
this is a t本文@来#源gaodai$ma#com搞$$代**码网搞代gaodaima码est function

For example three:

class A{   private function foo(){       echo "this is a test function"."<br>";   }   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

版权声明:本文为博主原创文章,未经博主允许不得转载。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php 静态绑定之static::
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址