suchen

Heim  >  Fragen und Antworten  >  Hauptteil

PHP7 calling scope与php5的不一样了?

今天在研究__call()和__callStatic()的时候读到了鸟哥的文章 PHP的Calling Scope

但是发现下面的代码在PHP5.5和PHP7中得到的结果不一样了?

<?php
 class Foo {     public function bar() {
         var_dump($this); //PHP5.5中打印的是A对象,PHP7是未定义,也就是NULL
     }
 } class A {     public function test() {
         Foo::bar();
     }
 } $a  = new A(); $a->test();?>

没找到PHP7关于调整这个的说明。谢谢大家指教


巴扎黑巴扎黑3026 Tage vor583

Antworte allen(1)Ich werde antworten

  • 面对疾风吧

    面对疾风吧2016-11-10 15:49:59

    有这个调整, 你在 PHP 7 的非向下兼容的里面可以找到, 并且在 PHP 5.6 中已经被标记为 DEPRECATED

    静态调用一个非静态方法, 会在静态调用中被提示未定义 $this, 并会报错。


    Antwort
    0
  • StornierenAntwort