By removing the ?, the function doesn't fail because it can no longer
handle a null, the _engine_ throws an error because you're no longer
allowed to _pass_ a null, it doesn't even execute the function itself.

If you were to either a) define it as ?Foo $foo = null in the first place,
or b) change ?Foo $foo to Foo $foo = null, it would execute without error.

However, the semantics of calling it has changed, in the case of ?Foo $foo,
you're allowing the caller to _explicitly_ call it and pass in a null, but
not to call it without specifying anything. If you add the default of null
(= null), you are now allowing them to call it without anything, and
_implicitly_ passing in a null. This could lead to very subtle bugs.

E.g. the behavior of passing executing with a null value for the argument
is something you should be consciously making a decision on, and passing in
null explicitly.

- Davey

On Wed, May 11, 2016 at 12:26 PM, Lester Caine <les...@lsces.co.uk> wrote:

> On 10/05/16 21:26, Levi Morrison wrote:
> > It can affect the results.
> >
> >     function foo(?Foo $param) {}
> >
> > If any code out there is calling foo with null then that code will now
> > break if you remove the question mark.
>
> Cart before Horse comes to mind ...
>
> If the function is going to fail if you pass in a null ... you check for
> the null before calling it. OK the '?' is a flag that you need to do
> that, but you really need proper documentation as to just what Foo
> expects. If I've handled the null case situation, the ? is redundant?
>
> I'm still failing to see an overall picture of what people are trying to
> achieve. Adding errors means that those errors need to be handled. If
> the function gets a 'null' then there is a reason, and either the
> function should not have been called ... workflow failed ... or the
> function should simply handle the 'null' case. If the '?' throws an
> error the workflow is broken after the event where a user code warning
> would be more helpful.
>
> --
> Lester Caine - G8HFL
> -----------------------------
> Contact - http://lsces.co.uk/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk
> Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Reply via email to