Re: [RFC] Nullable Return Type Declaration

From: Date: Thu, 14 Apr 2016 21:46:56 +0000
Subject: Re: [RFC] Nullable Return Type Declaration
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-92320@lists.php.net to get a copy of this message
>>Why not allow nullable types on parameters to avoid that wonkiness >>caused by default values of null? >> >> function foo(Bar | Null $b, $not_optional_param); >> >>This is much better. > > Yes but still a code smell to me. I'd need to know more about the > programmer's intent for foo(null, "value"). It > might be better to swap > order, or change the method name, or add another method... Who knows? Need > to take each case individually. Having a separate method instead of foo(null, "value") makes it difficult to use for the result of a function. Assume bar() returns Bar | Null; this would no longer work if they were separated: foo(bar(), "value") Functions are often composed so if something is the output of one function it will likely be the input to another. Thus if returning optionally null values is important to you so should optionally null parameters.

« previous php.internals (#92320) next »