SELECT NEW fails with ArrayType #5160

Open
opened 2026-01-22 14:59:59 +01:00 by admin · 0 comments
Owner

Originally created by @dbalabka on GitHub (Jun 20, 2016).

In case when we use SELECT NEW and trying to inject field with ArrayType we get here
https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php#L299
following warning:

Warning: unserialize() expects parameter 1 to be string, array given

because value already have been converted into array here:
https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php#L292

As quick solution I have fixed ArrayType::convertToPHPValue to return $value if it already converted.
https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/ArrayType.php#L53

    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        if (is_array($value)) {
            return $value;
        }

Doctrine ORM version: 2.4.8

Originally created by @dbalabka on GitHub (Jun 20, 2016). In case when we use `SELECT NEW` and trying to inject field with ArrayType we get here https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php#L299 following warning: ``` Warning: unserialize() expects parameter 1 to be string, array given ``` because value already have been converted into array here: https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php#L292 As quick solution I have fixed ArrayType::convertToPHPValue to return `$value` if it already converted. https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/ArrayType.php#L53 ``` public function convertToPHPValue($value, AbstractPlatform $platform) { if (is_array($value)) { return $value; } ``` Doctrine ORM version: 2.4.8
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5160