Re: Nullsafe array access can still emit a warning

From: Date: Wed, 24 Aug 2022 14:16:05 +0000
Subject: Re: Nullsafe array access can still emit a warning
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-118463@lists.php.net to get a copy of this message
On 24.08.2022 at 14:58, Gert de Pagter wrote: > I recently learned that using null safe on an array access can still > emit a warning when the array access is not defined. I kinda expected > it to work like a null coalesce and just short circuit there,without > the warning. > > Is there any chance this behaviour could be changed in a n upcoming > PHP version? I didn't see anything mentioned specifically about this > in the RFC. > > https://3v4l.org/1raa8 That behaves as documented[1]: | The nullsafe operator works the same as property or method access as | above, except that if the object being dereferenced is null then null | will be returned rather than an exception thrown. And particularly: | The effect is similar to wrapping each access in an is_null() check | first, but more compact. However, see e.g. <https://github.com/php/php-src/issues/7825#issuecomment-1100052164>. [1] <https://www.php.net/manual/en/language.oop5.basic.php#language.oop5.basic..nullsafe> -- Christoph M. Becker

« previous php.internals (#118463) next »