-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Closed
Copy link
Description
Symfony version(s) affected
7.4.2
Description
After upgrading Symfony to 7.4, the Serializer no longer respects @var PHPDoc annotations placed directly on constructor properties.
Previously, the following code worked correctly and the $data property was deserialized as an array of objects:
public function __construct(
/** @var SomeInnerClass[]|null */
public ?array $data,
) {
}After the upgrade, using this form results in $data being deserialized as an array of arrays instead of an array of SomeInnerClass objects.
Now deserialization works correctly only if the type information is moved to a constructor-level @param PHPDoc:
/**
* @param SomeInnerClass[]|null $data
*/
public function __construct(
public ?array $data,
) {
}How to reproduce
class SomeInnerClass
{
public function __construct(
public string $foo,
) {
}
}
class SomeClass
{
public function __construct(
/** @var SomeInnerClass[]|null */
public ?array $data,
) {
}
}
$object = $serializer->deserialize(
'{"data":[{"foo":"bar"}]}',
SomeClass::class,
'json'
);
// $object->data contains array of arrays instead of array of objectsPossible Solution
Additional Context
No response