Fwd: [PHP-DEV] Nullsafe

From: Date: Tue, 03 Nov 2020 19:18:57 +0000
Subject: Fwd: [PHP-DEV] Nullsafe
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-112166@lists.php.net to get a copy of this message
---------- Forwarded message --------- From: Eugene Sidelnyk <zsidelnik@gmail.com> Date: Tue, Nov 3, 2020 at 8:11 PM Subject: Re: [PHP-DEV] Nullsafe To: Benjamin Morel <benjamin.morel@gmail.com> When trying call a method, php falls with fatal error: https://3v4l.org/jk5Fp With nullsafe it silently returns null: https://3v4l.org/MhXtM Are there cases when we would like to use ordinary operator rather then nullsafe? In my opinion by default it should be safe On Tue, Nov 3, 2020, 7:58 PM Benjamin Morel <benjamin.morel@gmail.com> wrote: > Hi, > > It currently returns null but issues a warning (which can be, and often > is, converted to an exception by frameworks / custom error handlers): > https://3v4l.org/1ZkVC > > The new operator returns null with no warning: > https://3v4l.org/Wmun4 > > Benjamin > > On Tue, 3 Nov 2020 at 18:09, Eugene Sidelnyk <zsidelnik@gmail.com> wrote: > >> But currently working code doesn't fail with NullPointerException? >> Otherwise it would not be a working code. >> Early fail will be when we try return / pass anywhere this value >> >> On Tue, Nov 3, 2020, 6:48 PM Benjamin Morel <benjamin.morel@gmail.com> >> wrote: >> >>> On Tue, 3 Nov 2020 at 17:38, Eugene Sidelnyk <zsidelnik@gmail.com> >>> wrote: >>> >>>> I am wondering why don't we use ordinary -> >>>> operator with safe null >>>> handling? >>> >>> >>> Hi, >>> >>> - changing the current behaviour of -> would be a >>> huge BC break >>> - and if we need another reason, there are many situations where you do >>> want to fail early if the left operand is null, so the current operator is >>> a good fit >>> >>> — Benjamin >>> >>

« previous php.internals (#112166) next »