This is a bug that occurs when _ call and _ callStatic are inherited in php?

Source: Internet
Author: User
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.

  1. OnADefined in__callStatic, SoA::testThe static method does not exist, but it actually calls__callIt's up.
  2. IfBAndAIf the inheritance relationship is removed, all the above outputs areYES.
  3. Based on the above two points, I think php thinksA::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.

  1. OnADefined in__callStatic, SoA::testThe static method does not exist, but it actually calls__callIt's up.
  2. IfBAndAIf the inheritance relationship is removed, all the above outputs areYES.
  3. Based on the above two points, I think php thinksA::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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.