Re: Constant and expression ?
| From: | Alban LEROUX | Date: | Wed, 19 May 2010 21:18:44 +0000 |
| Subject: | Re: Constant and expression ? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-48356@lists.php.net to get a copy of this message | ||
On 2010-05-19 14:04:13 +0200, Ferenc Kovacs said:
On Wed, May 19, 2010 at 1:49 PM, Christian Schneider <cschneid@cschneid.com>wrote:That's could be very useful to define flag, something like that : class foo { const CASE_1 = 1 << 1; const CASE_2 = 1 << 2; const CASE_3 = 1 << 3; const CASE_4 = 1 << 4;fqqdk wrote:I think that is pretty subjective, but I did suprised when I found out, that the global scope constants behaves differently than the class consts. Allowing the class consts to be initialized in runtime(if neccessary) wouldn't breake any php application, only slow them. Can't we do something, to allow broader usage of consts without sacrificing performance? So I propose to add a new syntax: literal. literal should behave how the const behaved, and const should be initialized in runtime. maybe we could check from runtime, that the const was a dynamic value, or literal, and generate a notice for the developer to change the const to literal for gaining performance. What do you think? TyraelHow about extending the usage of the 'final' keyword to support ajava-likesyntax? class Foo { private static final $bar = 'ex' . 'pression';In my book "final" in Java gets an award for sickest abuse of a keyword. So no, I don't consider this an option. Simply use a class variable (or define()) if you need to store some runtime calculated value. "But <insert other language> can do this" alone is not sufficient as a reason to bloat PHP IMHO. - Chris
....} -- Alban Leroux seza@paradoxal.org Web developper