Bug #77344 [Nab]: Why is it judged to use __call
| From: | hongweichen8888 at sina dot com | Date: | Tue, 25 Dec 2018 02:46:42 +0000 |
| Subject: | Bug #77344 [Nab]: Why is it judged to use __call | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218609@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77344&edit=1
ID: 77344
User updated by: hongweichen8888 at sina dot com
Reported by: hongweichen8888 at sina dot com
Summary: Why is it judged to use __call
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: All
PHP Version: 7.2.13
Block user comment: N
Private report: N
New Comment:
class C { // without extends
function fun() {
A::test();
}
}
$obj2 = new C();
$obj2->fun();
// output: static
In this case, is $this not set?
Previous Comments:
------------------------------------------------------------------------
[2018-12-25 01:42:06] requinix@php.net
:: is the scope resolution operator. It is not the "static method call" operator. In fact
there is no such thing as a static method call operator.
------------------------------------------------------------------------
[2018-12-25 01:33:50] Wes dot example at example dot org
if $this is set, __call is called, otherwise __callStatic
that regardless of what's on the left of the :: operator
using parent:: or A:: is the same from php's perspective in this case
I know it's a bit odd. Perhaps php should have a different way to resolve the parent class than
the static method syntax
------------------------------------------------------------------------
[2018-12-25 01:12:27] hongweichen8888 at sina dot com
Description:
------------
When using the __call and __callStatic functionality on a parent class calls to A::method() will use
__call rather than the __callStatic.
Test script:
---------------
class A {
function __call($name, $arguments) {
echo "non-static\n";
}
static function __callStatic($name, $arguments){
echo "static\n";
}
}
class B extends A {
function fun() {
parent::test(); // with calling scope
A::test(); // ?
}
}
$obj = new B();
$obj->fun();
Expected result:
----------------
non-static
static
Actual result:
--------------
non-static
non-static
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77344&edit=1