Bug #70554 [Nab]: trait implementing __call is called for static magic method of 'use'ing class
| From: | mike@php.net | Date: | Fri, 25 Sep 2015 11:37:57 +0000 |
| Subject: | Bug #70554 [Nab]: trait implementing __call is called for static magic method of 'use'ing class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196234@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70554&edit=1
ID: 70554
Updated by: mike@php.net
Reported by: paul at salesintel dot com
Summary: trait implementing __call is called for static magic
method of 'use'ing class
Status: Not a bug
Type: Bug
Package: Unknown/Other Function
Operating System: Windows 10
PHP Version: 5.6.13
Block user comment: N
Private report: N
New Comment:
Please see http://php.net/forward_static_call
Previous Comments:
------------------------------------------------------------------------
[2015-09-23 02:57:00] laruence@php.net
it's have been explained many times in bugs :)
first of all , :: doesn't means "static" call. like:
parent::__construct();
php using calling scope to determinate whether it is a static call or not.
thus, in you example, when you calling TestClsss::magic_static() in test; it has a calling scope of
Testclass instance, thus it's not considered as a static call
so I am going to mark this as not a bug.
thanks
------------------------------------------------------------------------
[2015-09-22 20:48:36] paul at salesintel dot com
Description:
------------
A class that uses a trait that implements __call, and then from an instance method calls a static
method that does not exist, ends up calling __call in trait rather than __callStatic.
Test script:
---------------
trait TestTrait {
function __call($name, $args)
{
echo "instance method '$name' called.\n";
}
static function __callStatic($name, $args)
{
echo "static method '$name' called.\n";
}
}
class TestClass {
use TestTrait;
function test() {
// this ends up calling __call method in TestTrait ?!?!?! WTF?
TestClass::magic_static();
}
static function staticTest()
{
// this calls __callStatic as expected
TestClass::magic_static();
}
}
class TestClass2 {
function __call($name, $args)
{
echo "instance method '$name' called.\n";
}
static function __callStatic($name, $args)
{
echo "static method '$name' called.\n";
}
function test() {
// this calls __callStatic as expected
TestClass::magic_static();
}
static function staticTest()
{
// this calls __callStatic as expected
TestClass::magic_static();
}
}
$t = new TestClass();
$t->test();
$t->staticTest();
$t = new TestClass2();
$t->test();
$t->staticTest();
Expected result:
----------------
See inline comments in sample code
Actual result:
--------------
See inline comments in sample code
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70554&edit=1