[php-src] Issue #8204: Nullsafe Operator doesn't work with uninitialized properties

From: Date: Wed, 16 Mar 2022 08:14:54 +0000
Subject: [php-src] Issue #8204: Nullsafe Operator doesn't work with uninitialized properties
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240353@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8204 Comment Author: iluuu1994 Hi @iw-rylee! Properties with no types are implicitly set to null when the object is instantiated. This is not the case for properties with a type. They are initialized to the internal IS_UNDEF value which throws errors when accessed. The nullsafe operator by design guards against null but not the internal IS_UNDEF value. In general, all properties should be initialized after __construct. If they can't, it makes sense to make them nullable and set them to null. Marking them nullable makes users of the property aware that it might be null and that they might have to add a null-check of some sorts.

« previous php.bugs (#240353) next »