---------- Forwarded message --------- From: Eugene Sidelnyk <[email protected]> Date: Tue, Nov 3, 2020 at 8:11 PM Subject: Re: [PHP-DEV] Nullsafe To: Benjamin Morel <[email protected]>
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 <[email protected]> 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 <[email protected]> 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 <[email protected]> >> wrote: >> >>> On Tue, 3 Nov 2020 at 17:38, Eugene Sidelnyk <[email protected]> >>> 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 >>> >>
