Re: Nullable types and strict type-hinting with defaultnull value

From: Date: Sat, 25 Feb 2017 21:56:18 +0000
Subject: Re: Nullable types and strict type-hinting with defaultnull value
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-98354@lists.php.net to get a copy of this message
Hi, Niklas Keller wrote:
2017-02-25 16:12 GMT+01:00 Andrea Faulds <ajf@ajf.me>:
Rowan Collins wrote:
On 23 February 2017 09:15:27 GMT+00:00, "Michał" <aaatoja@o2.pl> wrote:
And what about situation when someone is forcing declare(strict_types=1)? I think, it's really a good place to force proper types. Including nulls.
strict_types controls the behaviour of *calling* functions, but the check here would have to be when *defining* the function: it would give an error that the function definition is invalid, like if you say function foo(int $bar='hello') Unless you had some other behaviour in mind?
In addition to this, if we wanted to prohibit implicit nullability in parameter definitions, we should have done it when we introduced declare(strict_types=1); in the first place, and that ship has sailed.
At that point we didn't even have nullable types, yet.
Sure.
Also, strict_types should do one thing, not all the things related to types.
I don't disagree. My point is that now that strict_types has been introduced, we have to maintain backwards-compatibility with code that uses it currently. We can't just tack new behaviour changes onto it without careful consideration, because that can break existing strict_types code. -- Andrea Faulds https://ajf.me/

« previous php.internals (#98354) next »