The assignment is not valid and would raise an error during the runtime.
This issue is raised for the following cases:
null-safe
operator ?->
on right side of assignment by referenceThe null-safe operator cannot be used with references.
$country = &$customer->getAddress()?->getCountry();
This would result in a fatal error.
null-safe
operator ?->
on the left side of assignmentThe null-safe
operator is read-only. It cannot write/assign values from it.
class Customer
{
private ?Address $address;
public function getAddress(): ?Address
{
return $this->address;
}
}
class Address
{
public string $country;
}
$customer->getAddress()?->country = 'NL';
function doStuff(\stdClass $s)
{
$s->wave() = 'test'; // Can't use method return value in write context
}