Bug #62333 [Nab]: Cannot statically call method to parent class
| From: | Sjon at hortensius dot net | Date: | Thu, 21 Jun 2012 08:15:16 +0000 |
| Subject: | Bug #62333 [Nab]: Cannot statically call method to parent class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-171406@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62333&edit=1
ID: 62333
User updated by: Sjon at hortensius dot net
Reported by: Sjon at hortensius dot net
Summary: Cannot statically call method to parent class
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
You describe my exact problem, but why deny this is a bug? I understand this
would be unfixable without breaking implementations that depend on this
behaviour, but I do not understand that you deny the huge inconsistency, thus
preferably fixable behaviour that PHP has here?
Previous Comments:
------------------------------------------------------------------------
[2012-06-19 08:32:13] cataphract@php.net
Not a bug. A::foo() is not necessarily a static call. Namely, if foo() is not static and there is a
compatible context ($this exists and its class is either the class of the target method or a
subclass of it), an instance call will be made. In your case, because you sort of have a static and
non-static foo() via magic, the non-static is preferred. You'll have to be creative, like maybe
calling __callstatic directly or using a closure.
------------------------------------------------------------------------
[2012-06-15 11:11:53] Sjon at hortensius dot net
Description:
------------
All static calls to a class-parent end up being non-static
Inconsistency clearly proven:
http://3v4l.org/Mkn0L
http://3v4l.org/1L3Wk (same, but without __call)
Test script:
---------------
See http://3v4l.org/Mkn0L
<?php
class A
{
public function __call($name, $args)
{
echo "Not static\n";
}
public static function __callStatic($name, $args)
{
echo "Static\n";
}
}
class B extends A
{
public function test()
{
forward_static_call(array('A', 'stuff'));
call_user_func(array('A', 'stuff'));
A::stuff();
}
}
class C
{
public function test()
{
forward_static_call(array('A', 'stuff'));
call_user_func(array('A', 'stuff'));
A::stuff();
}
}
A::test();
echo " = B =\n";
$b = new B();
$b->test();
echo " = C =\n";
$c = new C();
$c->test();
Expected result:
----------------
Static
= B =
Not static
Not static
Not static
= C =
Static
Static
Static
Actual result:
--------------
Static
= B =
Not static
Not static
Not static
= C =
Static
Static
Static
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62333&edit=1