From: dev98 at outlook dot de
Operating system: Windows x64, Manjaro Linux x64
PHP version: Irrelevant
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Unexpected behavior when utilizing __call and __callStatic from different scope
Description:
------------
When we utilize the __callStatic function with an appropriate static
call on the same class the magic function is defined while being in an
object scope, for some reason, the __call method will get invoked. This
seems very unintuitive as the php doc states:
"__call() is triggered when invoking inaccessible methods in an object
context."
We also tested it in 7.3.10-nts-Win32-VC15-x64,
5.6.40-nts-Win32-VC11-x86 and 8.0.10-nts-Linux-x64. Results are
consistent.
Testscript is crunched down in lines. For a nice formatting and code
comments please visit
https://stackoverflow.com/questions/69161169/unexpected-behavior-when-utilizing-call-and-callstatic-from-different-scopes
I have read the threads with bug id 51176 & 77344
and you might argue that "that's not a static call operator, its a scope
resolution operator." But since 2008 calling non static members
statically causes error messages. Further more when you replace the
calls on the non existing members with an forward_static_call, which
literally is documented with "Call a static method", it results in the
same behavior. Reproducible with replacing the calls
A::BLA(), B::BLA() with forward_static_call(array("A", "BLA")),
forward_static_call(array("B", "BLA"));
I understand the behavior daniel described in bug.php?id=51176
[2013-08-17 13:59 UTC] daniel dot ruthardt at zoesolutions dot eu, but
either the __call magic function catches the wrong call or
forward_static_call should be rather called
forward_scope_resolution_operator_call. Ive got the feeling here that
there is not a consent about how the :: operator should actually work.
Thanks in advance and lovely greetings from Germany
Test script:
---------------
class B {
public function __call($name, $arguments) {print(" __CALL on
B\r\n");}
public static function __callStatic($name, $arguments) {print("
__STATICCALL on B\r\n");}
}
class A {
public function __call($name, $arguments) {print(" __CALL on
A\r\n");}
public static function __callStatic($name, $arguments) {print("
__STATICCALL on A\r\n");}
public static function doMagicCall_from_staticContext() {
A::BLA(); // expect A::__callStatic, works
B::BLA(); // expect B::__callStatic, works
}
public function doMagicCall_from_objectContext() {
A::BLA(); // expect A::__callStatic, got $this->__call(), prints
"__CALL on A"
B::BLA(); // expect B::__callStatic, works
}
}
$a = new A();
print("1. Call from static context:\r\n");
A::doMagicCall_from_staticContext();
print("\r\n2. Call from object context:\r\n");
$a->doMagicCall_from_objectContext(); // provokes the behavior
Expected result:
----------------
1. Call from static context:
__STATICCALL on A
__STATICCALL on B
2. Call from object context:
__STATICCALL on A
__STATICCALL on B
Actual result:
--------------
1. Call from static context:
__STATICCALL on A
__STATICCALL on B
2. Call from object context:
__CALL on A
__STATICCALL on B
--
Edit bug report at https://bugs.php.net/bug.php?id=81436&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81436&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81436&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81436&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81436&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81436&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81436&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81436&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81436&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81436&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81436&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81436&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81436&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81436&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81436&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81436&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81436&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81436&r=mysqlcfg