Re: 5.4 regression: non-existent sub-sub keys now have values
| From: | Ferenc Kovacs | Date: | Fri, 25 Nov 2011 10:02:46 +0000 |
| Subject: | Re: 5.4 regression: non-existent sub-sub keys now have values | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-56625@lists.php.net to get a copy of this message | ||
On Fri, Nov 25, 2011 at 4:07 AM, Daniel Convissor <
danielc@analysisandsolutions.com> wrote:
> Hi Anthony:
>
> > isset($foo['bar'][1]['baz']) &&
> > is_array($foo['bar'][1])
> >
> > You don't need to check each level. Only the one above the key you're
> > looking at.
>
> Excellent thinking. One hitch... that goes fatal in 5.3 if $foo is a
> string.
> Here's how to write the test so it works the same way under 5.3 and 5.4:
>
yeah, and as you just noticed, one has to write less boilerplate code for
the current 5.4 to guarantee that $array["foo"]["bar"]["baz"] is set
and it
is an element of an array.
so I think we are just get to the point that everybody can agree that:
1, the string offset pseudo type and the chaining restriction sucks in 5.3,
as it can fatal even an isset call
2, the int type juggling for string offsets is un-intuitive, and it can
bite people.
3, because of 1 and 2, it writing variable checks which can handle type
mismatch for complex datatypes requires much boilerplate code.
The change introduced in 5.4 solves 1, doesn't touch 2, and makes 3 much
easier to solve.
So I think that we should keep the new behavior and focus on fixing 2,
either via documentation, or changing the behavior (raise a notice, or
don't accept non numeric values for string offsets at all).
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu