Bug #70554 [NEW]: trait implementing __call is called for static magic method of 'use'ing class
| From: | paul at salesintel dot com | Date: | Tue, 22 Sep 2015 20:48:39 +0000 |
| Subject: | Bug #70554 [NEW]: trait implementing __call is called for static magic method of 'use'ing class | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-196167@lists.php.net to get a copy of this message | ||
From: paul at salesintel dot com
Operating system: Windows 10
PHP version: 5.6.13
Package: Unknown/Other Function
Bug Type: Bug
Bug description:trait implementing __call is called for static magic method of 'use'ing
class
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 bug report at https://bugs.php.net/bug.php?id=70554&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70554&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70554&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70554&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70554&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70554&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70554&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70554&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70554&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70554&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70554&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70554&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70554&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70554&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70554&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70554&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70554&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70554&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70554&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70554&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70554&r=mysqlcfg