Skip to content

Casting an object to array does not unwrap refcount=1 references #8655

Closed
@nicolas-grekas

Description

@nicolas-grekas

Description

The following code produces the expected output on PHP < 8.1, but breaks on PHP >=8.1 see https://3v4l.org/L9WpO

class Foo
{
    public $foo;
}

function hydrate($properties, $object)
{
    foreach ($properties as $name => &$value) {
        $object->$name = &$value;
    }
};

$object = new Foo;

hydrate(['foo' => 123], $object);

var_dump(ReflectionReference::fromArrayElement((array) $object, 'foo'));

Resulted in this output:

object(ReflectionReference)#2 (0) {
}

But I expected this output instead:

NULL

PHP Version

8.1

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions