Doc #64059 [Opn->Csd]: Backwards Incompatible __callStatic Behavior
| From: | php at anthonybishopric dot com | Date: | Wed, 23 Jan 2013 23:38:14 +0000 |
| Subject: | Doc #64059 [Opn->Csd]: Backwards Incompatible __callStatic Behavior | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9464@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64059&edit=1
ID: 64059
User updated by: php at anthonybishopric dot com
Reported by: php at anthonybishopric dot com
Summary: Backwards Incompatible __callStatic Behavior
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: All
-PHP Version: 5.4.11
+PHP Version: 5.4.11, 5.3.x
Block user comment: N
Private report: N
New Comment:
Sorry, closing this - it appears this behavior was introduced sometime during
5.3.x - I tested on 5.3.3.
Also found https://bugs.php.net/bug.php?id=51176
which suggests this is not a bug.
Previous Comments:
------------------------------------------------------------------------
[2013-01-23 22:46:19] php at anthonybishopric dot com
Description:
------------
PHP 5.4 seems to have changed the behavior of __callStatic when invoked inside
the
object context of the defining class.
If both __call and __callStatic are defined, then inaccessible methods when
invoked with a static context are sent to __callStatic. However, inside an
object
context, inaccessible methods that use the 'static', 'self' or $classname to
invoke the method still get delegated to __call.
In 5.3, statically invoked, inaccessible methods delegated to __callStatic, no
matter where they are invoked.
This is a breaking change that should be listed on the PHP 5.4 backwards
incompatible change list. If this is an unintended change it should be fixed as
a
bug.
Test script:
---------------
class Magic{
public static function __callStatic($name, $args){
echo "__callStatic($name) invoked!\n";
}
public function __call($name, $args){
echo "__call($name) invoked!\n";
}
public function foo(){
Magic::bar(); // __call, but should be __callStatic
static::bar(); // __call, but should be __callStatic
self::bar(); // __call, but should be __callStatic
$this->bar(); // correctly is __call
}
}
$magic = new Magic();
$magic->foo();
Expected result:
----------------
__callStatic(bar) invoked!
__callStatic(bar) invoked!
__callStatic(bar) invoked!
__call(bar) invoked!
Actual result:
--------------
__call(bar) invoked!
__call(bar) invoked!
__call(bar) invoked!
__call(bar) invoked!
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64059&edit=1