Home > Article > Backend Development > Is PHP7 calling scope different from php5?
Today while studying __call()
and __callStatic()
, I read Brother Niao’s article PHP’s Calling Scope
But found that the results obtained by the following code are different in PHP5.5 and PHP7?
<code><?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(); ?></code>
I couldn’t find any instructions for adjusting this in PHP7. Thank you everyone for your advice
Today while studying __call()
and __callStatic()
, I read Brother Niao’s article PHP’s Calling Scope
But found that the results obtained by the following code are different in PHP5.5 and PHP7?
<code><?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(); ?></code>
I couldn’t find any instructions for adjusting this in PHP7. Thank you everyone for your advice
With this tweak, you can find it in PHP 7 which is not backwards compatible, and has been marked DEPRECATED in PHP 5.6
If you statically call a non-static method, you will be prompted that $this is not defined during the static call, and an error will be reported.
http://php.net/manual/en/migr...
http://m.runoob.com/php/php-d...