The only ambiguity is that if you expect an array, but actually have a string, $var[0]
will provide you with the first byte of the string instead of the first element of the array. This can lead to a big crash in the head and wonder why PHP gives you only the first character and not the whole array. This is even more true for non-numeric indices like $var['foo']
, which actually works if $var
is a string (yes, please don't ask). That is, it can make debugging a little more difficult if your program is primarily faulty.
There is no ambiguity for proper programs, since a variable cannot be a string and an array at the same time.
source share