Skip to content

Incorrect behavior of NullToStrictStringFuncCallArgRector #9762

Description

@LordSimal

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/768ba228-4ea7-4a4b-8a16-6859d993f8e1

<?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);
}

Responsible rules

  • NullToStrictStringFuncCallArgRector

Expected Behavior

Rector respects/remembers property states, which are fetched via the magic __get() method and therefore doesn't force the string casting

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions