Re: 5.4 regression: non-existent sub-sub keys now have values
| From: | Yasuo Ohgaki | Date: | Thu, 24 Nov 2011 21:53:42 +0000 |
| Subject: | Re: 5.4 regression: non-existent sub-sub keys now have values | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-56597@lists.php.net to get a copy of this message | ||
2011/11/25 Rasmus Lerdorf <rasmus@lerdorf.com>:
> On 11/24/2011 01:44 PM, Yasuo Ohgaki wrote:
>> Hi all,
>>
>> I should think twice before seding mail. "abc" as array index is
>> converted to 0 since it's not a integer. So with current code is
>> behave consistently with regards to string to long conversion.
>>
>> However,
>>
>> PHP 5.3
>> php -r '$s = "abc"; var_dump($s[0]["bar"]);'
>> PHP Fatal error: Cannot use string offset as an array in Command line
>> code on line 1
>>
>> PHP 5.4
>> ./php -r '$s = "abc"; var_dump($s[0]["bar"]);'
>> string(1) "a"
>>
>> Isn't it better to raise notice for accessing string by string index?
>> There is no use to allowing string index access to strings. I think
>> raising notice is feasible. Isn't it?
>
> String index access is still required since they are often numeric
> strings. We could add a notice for non-numeric strings, but the check
> would slow things down a bit.
How about enable notice only for PHP 5.4?
Programmer should check vars to see if it's an array, but finding the
cause of misbehavior without errors is pain for users.
I don't think we have to remove this feature, but it would be nice to
raise notice error for a while.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net