Hi all,

----- Original Message -----
From: "Yasuo Ohgaki"
Sent: Tuesday, June 09, 2015

Hi all,

On Tue, Jun 9, 2015 at 6:21 AM, Stanislav Malyshev <smalys...@gmail.com>
wrote:

> Would throwing a notice or a warning on array deferencing scalars
> be acceptable for PHP 7.0, or does this need an RFC?

I think this does need an RFC, and for 7.0, pretty much no new language
changes are acceptable anymore, since we're past the timeframe.


 <?php
 $foo = 42;
 $foo['bar']; // => NULL

This code cannot be right.
How about fix this as a simple bug?

I just realized this behavior a couple months ago, after being annoyed by "needing" to use isset() to avoid a Notice in rare cases. (I've always hate, hate, hated the isset() mess just trying to assign stuff -- I wanted a value-returning IFset() instead! Now we have ??, but still can't do var_dump($var ??).)

Anyway, I realized after checking the code that this is actually intentional and always has been, it seems. Really glad that I could rely on this and it makes things simpler and cleaner! :-)

Note that I'm referring to accessing NULL as an array (that I'd like to rely on). The other bool/int scalar without-a-notice case did/does seem a bit odd.

So if there's a change, how about only changing it for non-NULL values? Otherwise, this:

$v = NULL; $v[0][1][2][3][4][5][6][7][8][9];

is supposed to give 10 Notices?! That's dumb, and ugly, and looks like what the Pull Request is doing with the updated tests. Even worse in the case where the variable is undefined...

Regards,

--
Yasuo Ohgaki

Thanks,
Matt

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to