#50031 [Opn->Bgs]: get_called_class sometimes returns incorrect value
| From: | colder@php.net | Date: | Thu, 29 Oct 2009 11:58:07 +0000 |
| Subject: | #50031 [Opn->Bgs]: get_called_class sometimes returns incorrect value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-144068@lists.php.net to get a copy of this message | ||
ID: 50031
Updated by: colder@php.net
Reported By: abhibeckert at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Linux
PHP Version: 5.3.0
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
That's expected.
You do a non-static call to a non-static method from a unrelated class
using classname::method(), this will cause PHP to mess with the actual
call context, so that $this in foo::testFoo will be an object of bar.
Previous Comments:
------------------------------------------------------------------------
[2009-10-29 04:45:31] abhibeckert at gmail dot com
Description:
------------
If you declare class method without declaring it as static and then
call it as static, under certain circumstances get_called_class() will
return an incorrect result.
I realise it's technically incorrect to not declare a method as static,
But some code needs to be backwards compatible with previous versions
of
PHP, where declaring a method as static will give a syntax error.
Reproduce code:
---------------
class foo {
static public function test() { var_dump(get_called_class()); }
public function testTwo() { var_dump(get_called_class()); }
}
class bar {
public function test() { foo::test(); }
public function testTwo() { foo::testTwo(); }
}
echo "outside a class\n";
foo::test();
bar::testTwo();
echo "in a class\n";
$bar = new bar();
$bar->test();
$bar->testTwo();
Expected result:
----------------
outside a class
foo
foo
in a class
foo
foo
Actual result:
--------------
outside a class
foo
foo
in a class
foo
bar
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50031&edit=1