Bug #51765 [Opn->Bgs]: class constant has different setter behavior than global constant

From: Date: Fri, 07 May 2010 14:55:20 +0000
Subject: Bug #51765 [Opn->Bgs]: class constant has different setter behavior than global constant
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150247@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51765&edit=1 ID: 51765 Updated by: johannes@php.net Reported by: colin at sheaff dot net Summary: class constant has different setter behavior than global constant -Status: Open +Status: Bogus Type: Bug Package: Class/Object related Operating System: Any PHP Version: Irrelevant New Comment: 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 This is a limitation in the implementation. For the class constant we need a constant value at compile time and can't evaluate expressions. define() is a regular function, evaluated at run time and can therefore contain any value of any form. changing this would mean to add an execution phase in the compiler ... Previous Comments: ------------------------------------------------------------------------ [2010-05-07 15:17:53] colin at sheaff dot net Description: ------------ Global constants can be set using string concatenation and other global constants. This is useful. Class constants cannot be set using string concatenation or any functions, although they can be set to a global constant, or another class constant. The difference in setter behavior is confusing and limits utility of class constants. Test script: --------------- define( 'FOO', 'foo' ); define( 'BAR', FOO . 'bar' ); echo BAR . PHP_EOL; class Foobar { const foo = 'foo'; const bar = self::foo . 'bar'; } echo Foobar::bar; Expected result: ---------------- foobar foobar Actual result: -------------- Parse error: syntax error, unexpected '.', expecting ',' or ';' on line 8 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51765&edit=1

« previous php.bugs (#150247) next »