<?php
/**
* @property string|null $someProp
*/
final class Entity
{
protected array $_fields = [];
public function &__get(string $field): mixed
{
$value = null;
if (array_key_exists($field, $this->_fields)) {
$value = &$this->_fields[$field];
}
return $value;
}
}
$entity = new Entity();
if ($entity->someProp) {
preg_replace('/\r\n|\n|\r/', '', $entity->someProp);
}
Bug Report
Minimal PHP Code Causing Issue
See https://getrector.com/demo/768ba228-4ea7-4a4b-8a16-6859d993f8e1
Responsible rules
NullToStrictStringFuncCallArgRectorExpected Behavior
Rector respects/remembers property states, which are fetched via the magic
__get()method and therefore doesn't force the string casting