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

From: Date: Wed, 20 Nov 2013 21:38:13 +0000
Subject: Re: fix bug #53432 (Assignment via string index access on an empty string converts to array)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-70249@lists.php.net to get a copy of this message
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"

would be common pit hole when users are trying to use string as array of
chars.
I don't know why, but there are 436 FB likes! for this PR even if there is
no "likes!"
button on the page. There may be a lot of users that are unhappy with this
behavior.

Document and warn users?
Or should we change behavior even if it seems odd?

I don't mind at all setting up RFC to vote.
Any comments?

--
Yasuo Ohgaki
yohgaki@ohgaki.net


Thread (10 messages)

« previous php.internals (#70249) next »