DDC-1796: convertToPHPValue($value, $this->_platform) not run on scalarMappings #2260

Open
opened 2026-01-22 13:46:37 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 24, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user rivaros:

Maybe I am doing something wrong, but here is the case:

I created a custom Doctrine Type:

class BinaryType extends Type
{
        const BINARY = 'binary';

        public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
        {
            return sprintf('BINARY(%d)', $fieldDeclaration['length']);
        }

        public function getName()
        {
            return self::BINARY;
        }

        public function convertToPhpValue($value, AbstractPlatform $platform)
        {
            if ($value !== null) {
                $value= unpack('H*', $value);
                return array_shift($value);
            }
        }

        public function convertToDatabaseValue($value, AbstractPlatform $platform)
        {
            if ($value !== null) {
                return pack('H*', $value);
            }
        }
}

Now I have a simple table with Photographerguid field as binary (the custom type created) and run a simple query:

$q = $repository->createQueryBuilder('p')->select('p.name, p.surname, p.photographerguid')->where("p.name = 'peter'");
$result = $q->getQuery()->getResult();

The function convertToPhpValue is not run on the value of Photographerguid, so it returns %&@#!((@#

The reason is that in AbstractHydrator::_gatherRowData(array $data, array &$cache, array &$id, array &$nonemptyComponents) function
all fields of a query are determined as scalar (isScalar), and convertToPHPValue($value, $this->_platform) is not run on them.

What is the difference between scalarMappings and fieldMappings?
How to make data conversion work in both directions?

Originally created by @doctrinebot on GitHub (Apr 24, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user rivaros: Maybe I am doing something wrong, but here is the case: I created a custom Doctrine Type: ``` class BinaryType extends Type { const BINARY = 'binary'; public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return sprintf('BINARY(%d)', $fieldDeclaration['length']); } public function getName() { return self::BINARY; } public function convertToPhpValue($value, AbstractPlatform $platform) { if ($value !== null) { $value= unpack('H*', $value); return array_shift($value); } } public function convertToDatabaseValue($value, AbstractPlatform $platform) { if ($value !== null) { return pack('H*', $value); } } } ``` Now I have a simple table with Photographerguid field as binary (the custom type created) and run a simple query: ``` $q = $repository->createQueryBuilder('p')->select('p.name, p.surname, p.photographerguid')->where("p.name = 'peter'"); $result = $q->getQuery()->getResult(); ``` The function convertToPhpValue is not run on the value of Photographerguid, so it returns %<sup>&@#!(</sup>(@# The reason is that in AbstractHydrator::_gatherRowData(array $data, array &$cache, array &$id, array &$nonemptyComponents) function all fields of a query are determined as scalar (isScalar), and convertToPHPValue($value, $this->_platform) is not run on them. What is the difference between scalarMappings and fieldMappings? How to make data conversion work in both directions?
admin added the Bug label 2026-01-22 13:46:37 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2260