Re: [RFC] [VOTE] Typed properties v2
| From: | David Rodrigues | Date: | Sun, 23 Sep 2018 18:31:30 +0000 |
| Subject: | Re: [RFC] [VOTE] Typed properties v2 | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-103236@lists.php.net to get a copy of this message | ||
Em dom, 23 de set de 2018 às 13:09, Larry Garfield <larry@garfieldtech..com>
escreveu:
> 3) Object properties may be type hinted and the class author has until the
> end
> of the constructor to make sure they're fulfilled, otherwise TypeError on
> the
> spot (what I'm proposing).
>
Item 3 could not be enough, for instance:
<<<
class Example {
public /* string */ $string;
public function __construct() { static:: stringParameter
($this->string); }
public static function stringParameter(string $string) {}
}
new Example;
>>>
It will fail because __construct() uses an uninitialized non-nullable
property.
Maybe it should throw a new Exception like UninitializedPropertyException
when you try to read a uninitialized property like this case.
--
David Rodrigues