Please refer to the following code {code ...} the above code will output {code ...} when we directly use A: test elsewhere, it calls _ callStatic, and the output is normal YES. However, after we use A Class B to inherit A, we use A: test in A method of B. If we happen again in A... please refer to the following code:
test();B::stest();
The above code will be output
YESNOYES
When we useA::testIt calls__callStaticThe output is normal.YES.
However, when we use a classBInheritanceALaterBIn a methodA::testIf we happen to beADefined in__callMethod.A::testWill call__call.
Is this a bug in php?
------------------ Update -------------------
Here is the influence of the php scope mentioned in the blog (http://www.laruence.com/2012/06/14/26...) on the class call context, but after carefully reading it, I found that the problem here has some special characteristics.
- On
ADefined in__callStatic, SoA::testThe static method does not exist, but it actually calls__callIt's up.
- If
BAndAIf the inheritance relationship is removed, all the above outputs areYES.
- Based on the above two points, I think php thinks
A::test() == $this->test().
This is my conclusion, and according to @ Laruence, the php design is also mentioned here. But whether this design is reasonable can be done by yourself.
------------------ Update -------------------
I have found almost the same bug description in the php bug system.
Https://bugs.php.net/bug.php? Id = 52713
The final response shows that it has been fixed in PHP 5.3.4, but I have already used version 5.3.13. This error still exists.
Reply content:
See the following code.
test();B::stest();
The above code will be output
YESNOYES
When we useA::testIt calls__callStaticThe output is normal.YES.
However, when we use a classBInheritanceALaterBIn a methodA::testIf we happen to beADefined in__callMethod.A::testWill call__call.
Is this a bug in php?
------------------ Update -------------------
Here is the influence of the php scope mentioned in the blog (http://www.laruence.com/2012/06/14/26...) on the class call context, but after carefully reading it, I found that the problem here has some special characteristics.
- On
ADefined in__callStatic, SoA::testThe static method does not exist, but it actually calls__callIt's up.
- If
BAndAIf the inheritance relationship is removed, all the above outputs areYES.
- Based on the above two points, I think php thinks
A::test() == $this->test().
This is my conclusion, and according to @ Laruence, the php design is also mentioned here. But whether this design is reasonable can be done by yourself.
------------------ Update -------------------
I have found almost the same bug description in the php bug system.
Https://bugs.php.net/bug.php? Id = 52713
The final response shows that it has been fixed in PHP 5.3.4, but I have already used version 5.3.13. This error still exists.
The question is a bit confusing. Think about parent: test ()? Static or not lies in calling scope, not in: Symbol
Php is not very familiar with php, but it is normal If php class and C ++ call are the same...
Article 3:
Based on the above two points, I think here php considers A: test () = $ this-> test ().
This is incorrect ..
You call A: test () in the non-static function of B. php considers it to be A non-static function of Class A, that is, $ this-> :: test () instead of A: test ()
Call A: test () in the static function of B. php considers it to call the static function of Class A, that is, A: test ()
Of course, this is not true if it is in cpp, because cpp does not exist at the same time as php.
Public static test ();
Public test ();
These two functions ....
Static or not lies in calling scope, not in: Symbol. This learning is done.
Class {
Public function _ call ($ fun, $ args ){
Echo "_ call \ n ";
}
Public static function _ callstatic ($ fun, $ args ){
Echo "_ callstatic \ n ";
}
}
$ Ob = new ();
$ Ob-> test ();
A: test ();