On 23/09/2018 19:31, David Rodrigues wrote:
Em dom, 23 de set de 2018 às 13:09, Larry Garfield <la...@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.


Yes, there are various cases where checking at the end of the constructor is not enough. The general consensus is that we can't catch all of them without major changes to the language, but can catch some of the more common scenarios earlier than the current implementation does.


Maybe it should throw a new Exception like UninitializedPropertyException
when you try to read a uninitialized property like this case.


That's exactly what the current implementation will do, and what Larry's proposed addition would continue doing in cases where it can't be spotted at a "checkpoint" like the end of the constructor.


Regards,

--
Rowan Collins
[IMSoP]


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to