On Wed, Nov 23, 2011 at 3:14 PM, Daniel Convissor <
dani...@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

Reply via email to