I dimly recall, from my first readings of the PHP docs (more than 10 years ago) that the array-like syntax to access characters in arrays ($string[0]
) posed some ambiguity or undefined behaviour.
The O'Reilly PHP Pocket Reference (2nd ed) states:
To solve an ambiguity problem between strings and arrays, a new syntax has been introduced to dereference individual characters from strings:
$string{2}
This syntax is equivalent to
$string[2]
, and is preferable.
I understand that $string[2]
might be confusing, but I'm not sure how it could be ambiguous?
Furthermore: I wonder how the new syntax $string{2}
removes the ambiguity/confusion, considering that the curly braces (apparently) also work for "real" arrays.