On Sat, Jul 14, 2018 at 10:00 AM Rowan Collins <rowan.coll...@gmail.com> wrote: > > On 14 July 2018 15:37:32 BST, Levi Morrison <le...@php.net> wrote: > >> class Validity { > >> public \DateTimeInterface $validFrom; > >> public ?\DateTimeInterface $validTo = null; > >> } > > > >Even if this had a constructor we couldn't "trust" it because there > >are ways to skip constructors. > > Then the mechanisms should either be impossible with non-nullable properties, > or have a way to mark the object initialised. If not, the object created > would not be fully initialised, so accessing *the entire object* should be an > error, not just accessing the specific properties which are marked > non-nullable. > > I'm not claiming any of this is easy, but if you can't guarantee a property > has a valid value, what is the type hint actually for?
Whether it's a constructor, a factory method, or just a block of code near the `new` site: something has the responsibility for initialization. Once initialized the object provides guarantees unless you `unset` the property. It also provides the guarantee that if it is set then it will always be of the outlined type; this is a much stronger guarantee than we have today, which is... nothing. It's worth discussing, and if someone has a brilliant idea maybe we can proceed. However, in the absence of such an idea am I fine with the outlined semantics of the RFC. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php