Closed
Description
Symfony version(s) affected: x.y.z
Description
In version 5.0.10, one could use a PropertyAssessor
to fetch properties that were dynamically added to a class instance. In version 5.1.0, this functionality was removed/broken.
How to reproduce
class Person {
public function __construct(string $name) {
$this->name = $name;
}
}
$accessor = PropertyAccess::createPropertyAccessor();
$person = new Person("Joe Consumer");
/*
The following works correctly in version 5.0.10.
In versions 5.1.0 - 5.1.2 it throws an exception: "Can't get a way to read the property "name" in class..."
*/
$name = $accessor->getValue($person, 'name');
Possible Solution
One solution is to declare the property in the class definition, but this does not solve the issue for dynamically added properties.
Underlying regression is here:
The Person
class in this example is not an instanceof \stdClass
.
Additional context
Same issue reported when writing to a class instance: #37026