Description
Symfony version(s) affected: 5.1.9
Description
I don't know how to describe this bug without code, so here only the tl;dr. The results of the symfony serializer differ between composer install
and composer install --no-dev
.
How to reproduce
Consider the following code:
class Entry
{
public DateTimeInterface $dateTime;
}
class EntryData
{
/**
* @var Entry[]
*/
public array $entries;
}
$entryDataJson = '{"entries": [ { "dateTime": "2020-12-07T06:30:14.666Z" } ] }';
$result = $serializer->deserialize($entryDataJson, EntryData::class, 'json');
When having everything installed running composer install
then a var_dump on $result will look like this:
object(App\Model\EntryData)[685]
public array 'entries' =>
array (size=1)
0 =>
object(App\Model\Entry)[719]
public DateTimeInterface 'dateTime' =>
object(DateTimeImmutable)[721]
...
Now run composer install --no-dev
and run the code again. The result will now look like this:
object(App\Model\EntryData)[685]
public array 'entries' =>
array (size=1)
0 =>
array (size=1)
'dateTime' => string '2020-12-07T06:30:14.666Z' (length=24)
As you can see using the Serializer with composer install
will correctly deserialize the array of Entry
-objects. When using composer install --no-dev
you'll get a simple key-value based array instead. That is because in the symfony serializer the package phpdocumentor/reflection-docblock
is listed in require-dev
, not in require
. That leads to the PhpDocExtrator not being used with --no-dev
.
There is no Exception or anything, because in the FrameworkExtension
in registerPropertyInfoConfiguration
the PhpDocExtrator is simply not registered, if the phpDocumentor\Reflection\DocBlockFactoryInterface
doesn't exist.
Possible Solution
Either move phpdocumentor/reflection-docblock
from require-dev
to require
in composer.json. Or throw an exception (or at least a warning) if it's not installed along the symfony serializer.
IMO the dependency should be moved to require
, because it actually affects the results.