Bug #70554 [Opn->Nab]: trait implementing __call is called for static magic method of 'use'ing class

From: Date: Wed, 23 Sep 2015 02:57:01 +0000
Subject: Bug #70554 [Opn->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-196173@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: laruence@php.net Reported by: paul at salesintel dot com Summary: trait implementing __call is called for static magic method of 'use'ing class -Status: Open +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: 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 Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#196173) next »