9th May 2011 - 5 minutes read time
Question
What does the following code do?
define("MY_CONSTANT", array(1,2,3,4,5));
Answer
If this code is run it will produce the following error:
Warning: Constants may only evaluate to scalar values in test.php on line x
This is because only scalar values can be assigned to constants. A scalar value is any integer, float, string or boolean value and does not include arrays, objects or resources. Trying to set any non-scalar value as a constant will produce this error.