Re: [PHP] PHP5 class constants
On Thu, October 27, 2005 9:56 pm, Chris wrote: Though I suppose you could make an argument for using expressions that consist of only constant values. Actually... One could argue that so long as the programmer was willing to accept the consequences, there could be many legitimate circumstances in which one might WANT to utilize non-constant values for a const. Off the top of my head, there are: 1. A 'random' value which should be set for the course of the run/script 2. An environment 'variable' which comes from some external source. 3. A time() [and friends] value for profiling 4. Time computations such as (60*60*24). [Re #4] Not all Programmers have memorized and immediately recognize the value that 60*60*24 works out to, but they'd be hard pressed to not recognize those numbers as seconds/minutes/hours... In some languages, it is possible to use a pre-processor construct to have the interpreter/compiler compute a value in its first-pass, and to store that value as a constant in the program for actual execution. #. was what I recall from Lisp, about a decade ago. It was quite useful in many cases. I'm pretty sure C's macros and pre-processor macros and all that junk that gave me headaches was (partially) meant to accomplish the same thing. :-) I'm not sure PHP *needs* this feature, but I can certainly see that it would be useful to a lot more programmers than some stuff that is being worked on for PHP5+. :-) :-) :-) -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5 class constants
On Fri, 2005-10-28 at 01:02 +0200, Dragan Stanojevic - Nevidljivi wrote: [snip] and it works fine, I cannot define a constant by expression, like: class Foo { const AAA = 1 0; const BBB = 1 1; const CCC = 1 2; const DDD =1 3; } Well now, is this a bug, and I should file it, or is it, and why, normal? Not a bug. Read manual. From http://php.net/oop5.constants comes the following: The value must be a constant expression, not (for example) a variable, a class member, result of a mathematical operation or a function call. -- Jasper Bryant-Greene General Manager Album Limited e: [EMAIL PROTECTED] w: http://www.album.co.nz/ b: http://jbg.name/ p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303 a: PO Box 579, Christchurch 8015, New Zealand -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5 class constants
Jasper Bryant-Greene wrote: On Fri, 2005-10-28 at 01:02 +0200, Dragan Stanojevic - Nevidljivi wrote: [snip] and it works fine, I cannot define a constant by expression, like: class Foo { const AAA = 1 0; const BBB = 1 1; const CCC = 1 2; const DDD = 1 3; } Well now, is this a bug, and I should file it, or is it, and why, normal? Not a bug. Read manual. From http://php.net/oop5.constants comes the following: Oh, thanks Jasper... Pitty though, code would be a lot cleaner if the constant setting would allow it (put evaluated value in constant). bye, N:: -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5 class constants
Dragan Stanojevic - Nevidljivi wrote: Jasper Bryant-Greene wrote: On Fri, 2005-10-28 at 01:02 +0200, Dragan Stanojevic - Nevidljivi wrote: [snip] and it works fine, I cannot define a constant by expression, like: class Foo { const AAA = 1 0; const BBB = 1 1; const CCC = 1 2; const DDD = 1 3; } Well now, is this a bug, and I should file it, or is it, and why, normal? Not a bug. Read manual. From http://php.net/oop5.constants comes the following: Oh, thanks Jasper... Pitty though, code would be a lot cleaner if the constant setting would allow it (put evaluated value in constant). bye, N:: That constant is the same throughout all instances of the object, So you can't calculate the value based on instantiated info. Though I suppose you could make an argument for using expressions that consist of only constant values. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php