Home  >  Article  >  Backend Development  >  Is PHP7 calling scope different from php5?

Is PHP7 calling scope different from php5?

WBOY
WBOYOriginal
2016-12-01 00:56:52842browse

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

Reply content:

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...

Statement:
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