Take the 2-minute tour ×

How can I do that?

I have something like:

define($stuff.'_FOO', 'whatever');
echo $stuff.'_FOO';

and it doesn't work :(

I just want to echo the constant's value...

share|improve this question
add comment

2 Answers

up vote 12 down vote accepted

Check out constant().

In your case:

echo constant($stuff . '_FOO');
share|improve this answer
add comment

First make a constant:

define("FOO_BAR", "something more");

then you can get the value by using constant():

echo constant("FOO_BAR");

Read more about constants in the manual.

share|improve this answer
Note the OP is creating the constant name from a variable. So $stuff is intentional. –  Jason McCreary Apr 12 '11 at 2:31
yes, and I have a justified reason :D (need it to generate error messages for a set of forms, and the constant name contains the form ID) –  Alex Apr 12 '11 at 2:51
add comment

Your Answer


