> > I just encountered this language inconsistency when trying to remove > nullable from a constructor-promoted property: > > ``` > class MyClass > { > public function __construct( > public ?string $title = null // removing "?" here causes "Fatal > error: Cannot use null as default value" > ) { > $this->title = $title ?: resolveTitle(); > } > } > ``` > > Which is fine, there's a simple workaround, it was just surprising.
Property types don't infer nullability from the default value being null, so constructor properties don't allow it either. I'd say this is not an inconsistency, but rather a *consistency* with what this RFC proposes to deprecate and remove. Highly supportive of this RFC :) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php