Hello,
I stumbled upon this feature today and am wondering
why it exists:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
define('a', 'b');
$arr = array('a' => 'apple',
'b' => 'banana',
'c' => 'cranberry');
echo "a $arr[a] \n"; // apple
echo "b {$arr[a]} \n"; // banana (???)
echo "c {$arr['a']} \n"; // apple
echo "d $arr[b] \n"; // banana
echo "e {$arr[b]} \n"; // banana and E_NOTICE for
// undefined constant
echo "f {a} \n"; // {a}
echo $arr[a]; // banana (expected)
echo $arr['a']; // apple
?>
In otherwords, constants are looked for inside
strings under the following conditions:
a) It's an array key
b) {braces} are around the array
This seems like inconsistent behavior as that's
the only time they are looked for. This makes
sense outside of strings but inside of them only
if braces are used and with arrays? Please
explain. It seems to me that if someone wants to
use constants with array keys, don't put them in
strings.
Regards,
Philip Olson
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php