On 16 July 2018 00:52:53 BST, Dan Ackroyd <dan...@basereality.com> wrote: >On 14 July 2018 at 14:09, Rowan Collins <rowan.coll...@gmail.com> >wrote: >> Hi all, >> >> The current RFC proposes the next simplest solution, which is to >allow non-nullable types, and trust the user to initialise them before >use. > > >From the RFC: >> If a typed property does not have a default value, no implicit null >default value is implied (even if the property is nullable). >> Instead, the property is considered to be uninitialized. Reads from >uninitialized properties will generate a TypeError > >Are you miss-quoting the RFC? > >Because those two sentences are completely different.
There's no contradiction here; throwing an error when a property is *read* is not the same as enforcing that it always has a valid value. Compare with parameter type hints: function thing(Foo $foo) { $foo->bar(); } thing(null); The line that throws the error is thing(null), and that's the line that needs fixing. We don't allow the parameter in, and then throw an error when trying to use it, leaving the user to work out how it got there; that would defeat the purpose of the type hint. The difference between "uninitialised" and "null" is largely irrelevant: either way, the only way to run code like $foo->bar->baz() safely is to test the property before use. Or, to simply trust the user not to make a mistake. Regards, -- Rowan Collins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php