Edit report at http://bugs.php.net/bug.php?id=49431&edit=1
ID: 49431 Updated by: [email protected] Reported by: sweiss at stylesight dot com Summary: Cannot define class constant with constant value -Status: Open +Status: Bogus Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues Operating System: Debian PHP Version: 5.3.0 Block user comment: N Private report: N New Comment: Same as bug #30177 Previous Comments: ------------------------------------------------------------------------ [2009-09-01 16:27:30] sweiss at stylesight dot com Description: ------------ In the PHP documentation it states: "It is possible to define constant values on a per-class basis remaining the same and unchangeable. Constants differ from normal variables in that you don't use the $ symbol to declare or use them. "The value must be a constant expression, not (for example) a variable, a class member, result of a mathematical operation or a function call." This is however not entirely the case. If you define a constant within a class based on another constant, it will not work, despite the fact that it is a constant value. In the given example, X_CONST . "Y" is a constant composed of two other constants - no variables, class members, math expressions, or function calls. And, in fact, for normal, non-class constants, this is totally possible: define("Y_CONST", X_CONST . "Y"); is totally valid. At the very least the documentation should be updated to reflect simply that a class constant may only be defined as a simple scalar value, and not just any constant expression. Reproduce code: --------------- define("X_CONST", "Const"); class TestClass { const Y_CONST = X_CONST . "Y"; function test() { return self::Y_CONST; } } $a = new TestClass(); var_dump($a->test()); Expected result: ---------------- (string) "ConstY" Actual result: -------------- Parse error: syntax error, unexpected '.', expecting ',' or ';' in line 5 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=49431&edit=1
