|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-10-29 11:58 UTC] colder@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 00:00:02 2025 UTC |
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