Closed dakur closed 3 years ago
use setInitialized()
@dg So you mean that this setInitialized
is here to bypass this nullability problem?
Yes, because PHP calls them initialized https://www.php.net/manual/en/reflectionproperty.isinitialized.php.
They only make sense if the property has a type, otherwise = null
is unnecessary.
But it is true that an explicit setValue(null) could call setInitialized() ๐ค
Yes, that was actually the point of the issue โ API did not work in the way developer expected and did not throw any error on usage either.
The fix solves this, thanks. ๐
Version: 3.4.1
Bug Description
When printing class, there is this line:
which basically means that if I set value of
Property
tonull
intentionally, this value is not printed.Steps To Reproduce
E.g.
$property->setPrivate()->setValue(null)
generatesprivate $property;
But
$property->setPrivate()->setValue('test')
generatesprivate $property = 'test';
properlyExpected Behavior
It should generate
private $property = null;
Possible Solution
Mark null state with some constant instead of
null
. So it would look something like this: