Bug #76430 [NEW]: __METHOD__ inconsistent outside of method

From: Date: Fri, 08 Jun 2018 09:43:22 +0000
Subject: Bug #76430 [NEW]: __METHOD__ inconsistent outside of method
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215546@lists.php.net to get a copy of this message
From: nikic Operating system: PHP version: 7.2.6 Package: Scripting Engine problem Bug Type: Bug Bug description:__METHOD__ inconsistent outside of method Description: ------------ When __METHOD__ is used outside a method, but inside a class, it currently either returns the name of the class, or the name of the wrapping function, if the class is defined inside a function. There are three possible results that would be consistent, though I think the best one would be to return an empty string in both cases, as we are logically not inside a method or function -- the class declaration separates the scope. Test script: --------------- <?php class Foo { const X = __METHOD__; } function foo() { class Bar { const X = __METHOD__; } } foo(); var_dump(Foo::X); var_dump(Bar::X); Expected result: ---------------- string(0) "" string(0) "" or string(3) "Foo" string(3) "Bar" or string(0) "" string(3) "foo" Actual result: -------------- string(3) "Foo" string(3) "foo" -- Edit bug report at https://bugs.php.net/bug.php?id=76430&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76430&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76430&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76430&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76430&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76430&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76430&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76430&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76430&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76430&r=support Expected behavior: https://bugs.php.net/fix.php?id=76430&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76430&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76430&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76430&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76430&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76430&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76430&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76430&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76430&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76430&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76430&r=mysqlcfg

« previous php.bugs (#215546) next »