Re: fix bug #53432 (Assignment via string index access on an empty string converts to array)

From: Date: Wed, 20 Nov 2013 21:49:26 +0000
Subject: Re: fix bug #53432 (Assignment via string index access on an empty string converts to array)
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-70251@lists.php.net to get a copy of this message

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)

« previous php.internals (#70251) next »