Re: Non-nullable properties
| From: | Stanislav Malyshev | Date: | Mon, 16 Jul 2018 18:42:49 +0000 |
| Subject: | Re: Non-nullable properties | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102866@lists.php.net to get a copy of this message | ||
Hi!
> I agree with you. If someone really wants to have an "uninitialized" field
> on purpose, they should do that using the correct type declaration, i.e.:
>
> ?MyType $myNullable = null;
>
> When this was started I asked if it was possible to check types right after
> object has been constructed, but they said it was inefficient to do so.
> If this is still true, then I'm ok with checking on first access instead. I
> don't want even more overhead from runtime type checking.
> This is definitely not as bad as the "billion dollar mistake" though. The
> error still happens, but in a different place.
In Java, avoiding these kinds of errors - when the property is not
initialized - is almost trivial, and that's not what "billion dollar
mistake" is about. Lack of initialization for a final value (which is a
frequent case with property values) is detected by the compiler, and
most IDEs/analysis tools would alert of lack of initialization for
non-final value too. The problem is with usage on null as a substitution
for no value/error/unknown value and this value bleeding out into parts
of the code that don't know how to handle this situation.
--
Stas Malyshev
smalyshev@gmail.com