Re: Notice on non existing array key (on a boolean)
| From: | AllenJB | Date: | Tue, 25 Aug 2015 16:02:13 +0000 |
| Subject: | Re: Notice on non existing array key (on a boolean) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-87915@lists.php.net to get a copy of this message | ||
I have a pull request pending on this bug:
https://github.com/php/php-src/pull/1269
It's been discussed before ("Array dereferencing of scalars", 10th June 2015 - I'm pretty sure it was discussed at least once more since then too) and I was basically told it would require an RFC to get it accepted.
Unfortunately the RFC window had basically closed at that time (and work got busy shortly after), so now I've been waiting until 7.0 is clear (as well as me having the time to finish drafting the RFC).
AllenJB
On , Sherif Ramadan wrote:
Hey Nicolai, You're right. The notice is triggered by array_push behavior only, which means that $x = true; echo $x['foo']; doesn't trigger the notice, which is the same as your code above. Only write operations have historically resulted in this notice. I would agree that providing the notice would help someone debugging potentially buggy code like this. Not sure if this is something we can squeeze into 7.0.0 release at this point, but I would consider it a bug fix with BC rather than something that should be subject to current feature freeze. On Tue, Aug 25, 2015 at 9:35 AM, Nicolai Scheer <nicolai.scheer@gmail.com> wrote:Hi all, I'd expect the following code to throw a notice/warning: $x = true; $y = $x['foo']; It executes completely silently. $y is NULL afterwards, which is expected, since the right hand side of the assignment is undefined. If $x was an array (e.g. empty array), a E_NOTICE would be emitted. Can anyone shed a light on this behaviour? If accessing non existing array keys is worth a notice, shouldn't accessing an array index on a non array be worth a notice as well (maybe even a warning)? The other way round emits a warning (i.e. writing to an array key on a non array): $x = true; $x['foo'] = 'bar'; Warning: Cannot use a scalar value as an array ... Thanks for any insight, greetings Nico