On 25.08.2015 at 15:48, Sherif Ramadan wrote:

> 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.

See also <https://bugs.php.net/bug.php?id=54556>.

> On Tue, Aug 25, 2015 at 9:35 AM, Nicolai Scheer <nicolai.sch...@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,

-- 
Christoph M. Becker


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

Reply via email to