Re: Array dereferencing of scalars

From: Date: Wed, 10 Jun 2015 22:38:23 +0000
Subject: Re: Array dereferencing of scalars
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-86578@lists.php.net to get a copy of this message
Yasuo Ohgaki wrote: > On Wed, Jun 10, 2015 at 5:30 PM, Nikita Popov <nikita.ppv@gmail.com> wrote: > >> On Wed, Jun 10, 2015 at 8:53 AM, Stanislav Malyshev <smalyshev@gmail.com> >> wrote: >> >>>> <?php >>>> $foo = 42; >>>> $foo['bar']; // => NULL >>>> $v = NULL; >>>> $v[0][1][2][3][4][5][6][7][8][9]; // NULL >>>> >>>> this code is semantically wrong and I would like to have error/exception >>>> for such >>>> erroneous codes. It's inconsistent with array object, too. >>> >>> Why it's wrong? You try to get that's something not there, you get NULL. >>> I don't see anything wrong. Adding fatal error about every little thing >>> that isn't as expected never was how PHP worked. >> >> I agree with what other people have said here: We should keep the behavior >> for NULL, but drop the nonsense for other types - (42)[24] not throwing a >> notice is quite ridiculous, that seems like a pretty obvious bug to me. > > I agree that NULL is debatable. In PHP, NULL is treated as 0/false by its > context. > It's simpler if we get rid of the behavior altogether. IMO. > > Anyway, removing undefined behavior from other types may be good enough so > I don't insist. +1 -- Christoph M. Becker

« previous php.internals (#86578) next »