I'm sorry to jump in mid-stream here (I've been offline for a while), but
was
$constant_value=${constant_name};
suggested?
eval's spook me, so I would prefer this solution over the working
suggestion you received.
This works for me on 4.0.4:
$test_name="ta_dah";
define("constant_name","test_nam
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] (Geoff Caplan) wrote:
> I am trying to create a constant name dynamically and then get at the
> value.
>
> // We set up the constant
> define( CONSTANT_1 , "Some value" ) ;
>
> // Later we try to use it dynamically ...
> $constant_number = 1 ;
Hi folks
I had 2 suggestions from the list:
1) indirection - $constant_value = $$constant_name ;
I had already tried this, but couldn't get it to work. Unless I am
missing something it just gives an "Undefined Variable" error.
2) eval("\$constant_value = $constant_name;") ;
This does work. Th
You need another level of indirection. Try:
$constant_value = $$constant_name ;
-Original Message-
From: Geoff Caplan [mailto:[EMAIL PROTECTED]]
Sent: 27 March 2001 14:19
To: PHP General List
Subject: [PHP] Dynamic constant names
Hi folks
I am trying to create a constant name dynamic
4 matches
Mail list logo