Re: 5.4 regression: non-existent sub-sub keys now have values
| From: | Ferenc Kovacs | Date: | Wed, 23 Nov 2011 15:40:25 +0000 |
| Subject: | Re: 5.4 regression: non-existent sub-sub keys now have values | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-56516@lists.php.net to get a copy of this message | ||
On Wed, Nov 23, 2011 at 4:31 PM, Daniel Convissor <
danielc@analysisandsolutions.com> wrote:
> Hi Again Folks:
>
> On Wed, Nov 23, 2011 at 09:14:09AM -0500, Daniel Convissor wrote:
> > $a = 'foo';
> > echo $a['blah'] . "\n";
> >
> > But that second one echos out "f". This is a huge WTF.
>
> Two things for the record on this front. First, i've been actively
> using PHP for, what, ten years or so, and have never run into this
> behavior before. Second, this behavior turns the following one liner:
>
> if (isset($arr['package']['attribs']['version'])) {
>
> Into this:
>
> if (is_array($arr)
> && array_key_exists('package', $arr)
> && is_array($arr['package'])
> && array_key_exists('attribs', $arr['package'])
> && is_array($arr['package']['attribs'])
> && array_key_exists('version',
> $arr['package']['attribs'])
> &&
> !empty($arr['package']['attribs']['version']))
> {
>
it is only necessary if you can't guarantee your data structure (so that
you can get a string where you expect an array)
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu