Re: 5.4 regression: non-existent sub-sub keys now have values
| From: | Ferenc Kovacs | Date: | Wed, 23 Nov 2011 14:19:42 +0000 |
| Subject: | Re: 5.4 regression: non-existent sub-sub keys now have values | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-56505@lists.php.net to get a copy of this message | ||
On Wed, Nov 23, 2011 at 3:14 PM, Daniel Convissor <
danielc@analysisandsolutions.com> wrote:
> Hi Stas:
>
> > It's actually very simple. Take variable $a which is a string
> > ("foo"). Now it you do $a[0] that would produce first letter - "f".
> > Now here's a tricky part - if you do $a['blah'] it would convert
> > 'blah' to number, get 0 and return the same letter "f".
>
> To me, this is the bug. $a['blah'] does not exist. An undefined index
> notice should be raised. The key "blah" should not be converted to 0.
> The following two things should behave the same:
>
> $b = array('exists' => 'foo');
> echo $b['blah'] . "\n";
>
> $a = 'foo';
> echo $a['blah'] . "\n";
>
> But that second one echos out "f". This is a huge WTF.
and the following should also behave the same:
$a = 'foo';
echo $a[2];
echo $a['2'];
echo $a['2 cats'];
because this is how the type juggling works in php:
http://php.net/manual/en/language.types.type-juggling.php
if we allow strings to be used as indexes for strings, we have to be
consistent with what we have already.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu