|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-12-29 12:23 UTC] jani@php.net
-Status: Open
+Status: Bogus
-Package: Feature/Change Request
+Package: *General Issues
[2010-12-29 12:23 UTC] jani@php.net
[2010-12-29 12:24 UTC] jani@php.net
-Package: *General Issues
+Package: Scripting Engine problem
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 04:00:01 2025 UTC |
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