#50031 [NEW]: get_called_class sometimes returns incorrect value

From: Date: Thu, 29 Oct 2009 04:45:31 +0000
Subject: #50031 [NEW]: get_called_class sometimes returns incorrect value
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-144064@lists.php.net to get a copy of this message
From: abhibeckert at gmail dot com Operating system: Linux PHP version: 5.3.0 PHP Bug Type: Scripting Engine problem Bug description: get_called_class sometimes returns incorrect value 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 bug report at http://bugs.php.net/?id=50031&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50031&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50031&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50031&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50031&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50031&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50031&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50031&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50031&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50031&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50031&r=support Expected behavior: http://bugs.php.net/fix.php?id=50031&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50031&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50031&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50031&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50031&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=50031&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50031&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50031&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50031&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50031&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50031&r=mysqlcfg

« previous php.bugs (#144064) next »