constant definition doesn't return value?
Quote:
> I was hoping that define() returns a value. Consider the following:
> echo define('HELLO', 3);
> Which outputs "1". Thats a pitty becouse otherwise one could use it as
> follows:
> $max_message_id = 0;
> $error_array[ define(E_SOME_ERROR_MESSAGE, $max_message_id++)] = "You
> should not do that, it is illegal";
> $error_array[ define(E_SOME_OTHER_ERROR_MESSAGE, $max_message_id++)] =
> "Dont do that again";
> Is my view correct on the define() language construct?
I don't understand why you would think that define() would return the value
that you set a constant to, or even the name of the constant. The reason it
returns 1 is because define is returning the answer to the question:
Did the function define('YOUR_CONSTANT', 5) execute properly? TRUE or 1 :
FALSE or 0;
In other words, there are only 2 values that define() will return. On the
other hand, if you define your constants first, you can use the following:
define('E_SOME_ERROR_MESSAGE', $max_message_id);
$error_array[E_SOME_ERROR_MESSAGE] = "You should not do that, it is
illegal";
$max_message_id++;
define('E_SOME_OTHER_ERROR_MESSAGE', $max_message_id);
$error_array[E_SOME_OTHER_ERROR_MESSAGE] = "Dont do that again";
You can use variables to set constants, but you cannot redefine a constant.