From: Operating system: PHP version: 5.4.3 Package: Scripting Engine problem Bug Type: Bug Bug description:Global/namespace constants are not hoisted
Description: ------------ "const" Declarations outside a class were introduced in PHP 5.3, and they only support static "compile-time" expressions, unlike define(). Function and classes declarations are hoisted to the top of the file, so you can call them before the line they are defined in. This doesn't happen with "const", although it's expected as a matter of consistency. This leads to the following odd problem: <?php namespace foo; func(); // Warning, and prints "NOT_HOISTED" const NOT_HOISTED = 123; func(); // prints "123" function func() { echo NOT_HOISTED; } Please make "const" consistent with the rest of the language, and hoist it together with function and class declarations. Expected result: ---------------- To print "123" in both cases, no warning. Actual result: -------------- Referring to a const before the line it's declared in results in an error and magical string casting (as if it doesn't exist). -- Edit bug report at https://bugs.php.net/bug.php?id=62076&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62076&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62076&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62076&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=62076&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62076&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=62076&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=62076&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=62076&r=needscript Try newer version: https://bugs.php.net/fix.php?id=62076&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=62076&r=support Expected behavior: https://bugs.php.net/fix.php?id=62076&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=62076&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=62076&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=62076&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62076&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=62076&r=dst IIS Stability: https://bugs.php.net/fix.php?id=62076&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=62076&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=62076&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=62076&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=62076&r=mysqlcfg