Re: Non-nullable properties

From: Date: Mon, 16 Jul 2018 14:55:31 +0000
Subject: Re: Non-nullable properties
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-102852@lists.php.net to get a copy of this message
On 16 July 2018 at 14:28, Marco Pivetta <ocramius@gmail.com> wrote: > These don't really need explicit tests in most cases, but rather static > analysis (currently happening via docblocks). Static analysis tools like > vimeo/psalm already pick this up. > Then why do we need the type hints at all? > I'd even be happy to get type hints that only have effect on > ReflectionProperty#getType() as a massive improvement over the > current > situation we've monkey-patched us into, but the patch is indeed consistent > with PHP's current state. > I disagree that it's consistent. It introduces an entirely new kind of null reference ("declared but uninitialised"), which will require *more* careful checks than forcing the value to be initially null, and will undoubtedly further annoy those who already claim that isset() is broken (the RFC doesn't even mention it, but I presume uninitialised properties will return false from isset(), but throw an error from is_null()). If all typed properties require a valid default value, the patch is simpler, errors are raised at a line where you can fix them, and the language remains consistent - if you're promised a Foo, you get a Foo, not a "whoops, why isn't there a Foo here?" error. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#102852) next »