Re: [RFC] [VOTE] Typed properties v2
| From: | Robert Korulczyk | Date: | Sun, 23 Sep 2018 20:16:54 +0000 |
| Subject: | Re: [RFC] [VOTE] Typed properties v2 | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-103240@lists.php.net to get a copy of this message | ||
> Just to be sure you don’t miss the herd that this elephant is concealing:
>
> In addition, you *must* forbid unset() on those properties...
Shouldn't we delegate the whole problem to object type resolving and make it more strict? Right
now properties are not guaranteed at all - you can
have
Foo class with $bar property, but it does not mean that instance of
Foo will actually have this property. The current implementation of
typed properties seems to be pretty consistent with this. Type check gives you nothing as far as the
object's properties are concerned.
But if $foo instanceof Foo or function (Foo $foo) will test that
$foo:
1. is an instance of Foo,
2. has all properties defined in Foo,
3. all typehinted properties are initialized,
then the problem will basically disappear - you can protect yourself from propagating uninitialized
object by typehints or type checks (which you
would probably do anyway). And you still can create an uninitialized object for lazy initialization
or whatever you want.
--
Regards,
Robert Korulczyk