Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Recover support to write properties for non stdClass objects  #37026

Closed
@ScreamingDev

Description

@ScreamingDev

Symfony version(s) affected: 5.1 and lower

Description
When generating entities (e.g. via nelmio/alice) it was long possible to write values into existing properties.
But now it seems like the property accessor does only allows this for instances of stdClass .

Possibly since this change: symfony/property-access@0583535

So when a class like

class Foo {
}

has no property but an object gets a property later on like

$o = new Foo();
$o->bla = null;

then the PropertyAcessor is no longer able to write into this existing property
and instead throws the NoSuchPropertyException exception with a "Could not determine access type" message.

Possible Solution

Drop the explicit check for stdClass

} elseif (property_exists($object, $property)) {
            $object->$property = $value;
        }

see https://github.com/symfony/property-access/blob/0583535d2cfa597ccd6a8e75f6f3bf5a138a5541/PropertyAccessor.php#L509

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