Re: Non-nullable properties
| From: | Rowan Collins | Date: | Sat, 14 Jul 2018 15:59:49 +0000 |
| Subject: | Re: Non-nullable properties | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102824@lists.php.net to get a copy of this message | ||
On 14 July 2018 15:37:32 BST, Levi Morrison <levim@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?
Regards,
--
Rowan Collins
[IMSoP]