Re: fix bug #53432 (Assignment via string index access on an empty string converts to array)
| From: | Nikita Popov | Date: | Wed, 20 Nov 2013 15:26:38 +0000 |
| Subject: | Re: fix bug #53432 (Assignment via string index access on an empty string converts to array) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70236@lists.php.net to get a copy of this message | ||
On Wed, Nov 20, 2013 at 12:47 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> Hi all,
>
> This PR seems good fix for 5.6.
>
> https://github.com/php/php-src/pull/463
>
> Test script:
> ---------------
> $a = ''; // empty string
> $a[10] = 'a';
> echo $a; // "Array"
>
> $b = ' '; // non empty string
> $b[10] = 'b';
> echo $b; // " b"
>
> Expected result:
> ----------------
> " a"
> " b"
>
> Actual result:
> --------------
> "Array"
> " b"
>
> Current behavior does not make sense.
>
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.
Nikita