Re: Array dereferencing of scalars
| From: | Christoph Becker | Date: | Tue, 09 Jun 2015 11:21:18 +0000 |
| Subject: | Re: Array dereferencing of scalars | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-86515@lists.php.net to get a copy of this message | ||
Yasuo Ohgaki wrote:
> I fully agree that current behavior could be used meaningful ways. However,
>
> <?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.
>
> Raising exception/error is correct behavior for types that aren't array.
> To avoid errors, users should use isset()/is_array()/etc.
I agree that the code is not clean, and that an isset check is
appropriate, particularly as one could do:
$v = NULL;
$v[0][1][2][3][4][5][6][7][8][9] ?? NULL; // NULL
> Since we have debate for this PR, this PR would be good for RFC targeting
> PHP 7.1.
It seems to me that raising an exception or throwing an error (instead
of a notice) could be too much of a BC break for a minor version.
--
Christoph M. Becker