Edit report at http://bugs.php.net/bug.php?id=49542&edit=1
ID: 49542
Comment by: matt dot lubner at gmail dot com
Reported by: mjs at beebo dot org
Summary: __callStatic() only invoked if instance method does
not exist
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: Ubuntu
PHP Version: 5.3.0
Block user comment: N
New Comment:
With PHP 5.3.2, if the instance method bar() is *not* public, and
__callStatic()
*is*, __callStatic() will be invoked, because bar() won't be in scope.
Unfortunately, this seems like a horribly hacked work-around. Ideally,
public
instance methods should not be in scope from a static context, so
__callStatic()
will be called instead.
Previous Comments:
------------------------------------------------------------------------
[2009-09-13 14:34:38] mjs at beebo dot org
Description:
------------
A static call to Foo::bar() does not invoke __callStatic() if an
instance method bar() exists.
One reason you might want this is to convert static calls to Foo::bar()
to the equivalent operation on a singleton:
public static function __callStatic($name, $args) {
$obj = self::getInstance();
return call_user_func_array(array($obj, $name), $args);
}
In the sample code below, __callStatic() is not invoked even though the
caller has deliberately initiated a static call.
Reproduce code:
---------------
<?php
class Foo {
public static function __callStatic($name, $args) {
echo "In __callStatic()\n";
}
public function bar() {
echo "In bar()\n";
}
}
echo Foo::bar();
Expected result:
----------------
In _callStatic()
Actual result:
--------------
PHP Strict Standards: Non-static method Foo::bar() should not be called
statically in /mnt/hgfs/workspace/scratch/wart1.php on line 15
Strict Standards: Non-static method Foo::bar() should not be called
statically in /mnt/hgfs/workspace/scratch/wart1.php on line 15
In bar()
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=49542&edit=1