Re: fix bug #53432 (Assignment via string index access on an empty string converts to array)
On 20/11/13 21:38, Yasuo Ohgaki wrote:
Hi Nikita,
On Thu, Nov 21, 2013 at 12:26 AM, Nikita Popov <nikita.ppv@gmail.com> wrote:
The current behavior is that anything "falsey" (e.g. null, false and the
empty string) is silently cast to array when an array operation is applied
to it. I don't like that behavior, but it's somewhat internally consistent
now. Changing it for strings *only* seems a bit weird.
Persuasive argument.
I prefer to change the behavior if I have to choose, though.
$a = ''; // empty string
$a[10] = 'a';
echo $a; // "Array"
Just my 2 cents, but that definitely looks like a situation that might crop up in real code unintentionally, and it violates the Principle of Least Astonishment IMO. Consider a hypothetical function which returns a modified string. If we've ended up with an empty string being passed into it, then it suddenly returning an Array is not what you expect, and might horribly break code that assumes the result won't be a string.
--
Andrea Faulds
http://ajf.me/
Thread (10 messages)