Jay Blanchard wrote:
[snip]
it doesn't fail and is not imho foolish by definition ... the value of the
constant,
although changing stays the same for the duration of the request,
IIRC Rasmus himself once mentioned that it can be useful to be able to set
a constant to a 'dynamic' value like this
Jay,
gonna have to correct you on this lot (sorry ;-)
Jay Blanchard wrote:
[snip]
is there a way to dynamically define a class constant during runtime
in PHP 5?
for example I would like to achieve the result of something like:
class Example {
const FOO = bar();
}
However this
[snip]
it doesn't fail and is not imho foolish by definition ... the value of the
constant,
although changing stays the same for the duration of the request,
IIRC Rasmus himself once mentioned that it can be useful to be able to set
a constant to a 'dynamic' value like this - nuff said really :-)
Dynamically setting a constant would break the very rule of it being a
constant in the first place.
a constant is something that does not change it cannot be dynamic.
On Wednesday 07 December 2005 12:00, Jeffrey Sambells wrote:
is there a way to dynamically define a class constant during
[snip]
is there a way to dynamically define a class constant during runtime
in PHP 5?
for example I would like to achieve the result of something like:
class Example {
const FOO = bar();
}
However this would obviously give a parse error.
I know it is possible with variables but I
It would be foolish (and would fail anyhow) to do something like this;
Nope. :P
?php
define(RANDOM, rand(5,12));
var_dump(RANDOM);
?
int(12)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[snip]
It would be foolish (and would fail anyhow) to do something like this;
Nope. :P
?php
define(RANDOM, rand(5,12));
var_dump(RANDOM);
?
int(12)
[/snip]
Wow, that should fail. But you did have use var_dump() to get it, which may
be slightly counter-intuitive. I just did this
function
[snip]
Wow, that should fail. But you did have use var_dump() to get it, which may
be slightly counter-intuitive. I just did this
function realRand($x){
$x = $x * rand(5,10);
return $x;
}
define(RANDOM, realRand(1.2));
var_dump(RANDOM);
and it returns floats. Well, I'll be
Stephen Leaf wrote:
Dynamically setting a constant would break the very rule of it being a
constant in the first place.
Did you say something about my Java?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
The point was more that the constant's value is 'defined' at the
beginning of the script, and is constant and non changing throughout
the entire execution of the script. But I was looking for a way to give
it a namespace inside a class rather than just defining in in the
global scope so that I
10 matches
Mail list logo