Edit report at http://bugs.php.net/bug.php?id=42355&edit=1
ID: 42355 Comment by: dirarck at gmail dot com Reported by: adam dot huttler at fracturedatlas dot org Summary: can't concatenate when defining class constant Status: Bogus Type: Bug Package: Class/Object related Operating System: Linux PHP Version: 5.2.3 Block user comment: N Private report: N New Comment: Maybe a solution for this issue could be using defined constants, something like this: [ START ] define('ROOT_DIR', dirname('..' . Constants::DS)); define('ACTIONS_DIRECTORY', APPLICATION_PATH . Constants::DS . 'actions' . Constants::DS); define('VIEWS_DIRECTORY', APPLICATION_PATH . Constants::DS . 'views' . Constants::DS); class Constants { const ROOT_DIR = ROOT_DIR; const DS = DIRECTORY_SEPARATOR; const ACTIONS_DIRECTORY = ACTIONS_DIRECTORY; const VIEWS_DIRECTORY = VIEWS_DIRECTORY; } [ END ] Sorry by my poor english, maybe someone could correct me... Previous Comments: ------------------------------------------------------------------------ [2007-08-21 10:26:04] adam dot huttler at fracturedatlas dot org Thanks for the reply. I suspected this would be marked bogus, since the behavior is consistent with how object properties need to be initialized, etc. Can this be considered a feature request? I do understand the runtime/compile time challenge. But it seems like there may be ways around it (e.g. late static binding is getting addressed). ------------------------------------------------------------------------ [2007-08-21 06:22:09] der...@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php You can only initialize class constants with constant values. You pass a statement which has to be evaluated at runtime, while the class constants are defined at compile time which comes earlier. ------------------------------------------------------------------------ [2007-08-20 22:18:06] adam dot huttler at fracturedatlas dot org Description: ------------ When defining a global constant, you can concatenate a string to another constant. Doing this with class constants causes a parse error. If this isn't considered a bug, please consider it a feature request, as it would be very useful for configuration (especially file paths). Thanks. Reproduce code: --------------- define('FOO', 'foo'); class Foobar { const MESSAGE = FOO . 'bar'; } echo Foobar::MESSAGE; Expected result: ---------------- foobar Actual result: -------------- Parse error: syntax error, unexpected '.', expecting ',' or ';' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=42355&edit=1