SimpleObjectHydrator produces wrong values with inheritance table and simple array type #5229

Closed
opened 2026-01-22 15:02:03 +01:00 by admin · 5 comments
Owner

Originally created by @w3sami on GitHub (Aug 24, 2016).

Originally assigned to: @Ocramius on GitHub.

I am getting empty array instead of array with some values, since SimpleObjectHydrator converts the value with convertToPHPValue

line 129 $value = $type->convertToPHPValue($value, $this->_platform);

this doesent play well with the null check below

line 134:
// Prevent overwrite in case of inherit classes using same property name (See AbstractHydrator)
if ( ! isset($data[$fieldName]) || $value !== null) {
$data[$fieldName] = $value;
}

since arrayType->convertToPHPValue returns [] when null, resulting in a leak from the wrong left joined table.

solution is easy, dont use the converted value in the if, but instead a raw value.

eg line 125 + $rawValue = $value;
and
136: if ( ! isset($data[$fieldName]) || $rawValue !== null) {

sorry I don't have time to write a pr with tests

Originally created by @w3sami on GitHub (Aug 24, 2016). Originally assigned to: @Ocramius on GitHub. I am getting empty array instead of array with some values, since SimpleObjectHydrator converts the value with convertToPHPValue line 129 $value = $type->convertToPHPValue($value, $this->_platform); this doesent play well with the null check below line 134: // Prevent overwrite in case of inherit classes using same property name (See AbstractHydrator) if ( ! isset($data[$fieldName]) || $value !== null) { $data[$fieldName] = $value; } since arrayType->convertToPHPValue returns [] when null, resulting in a leak from the wrong left joined table. solution is easy, dont use the converted value in the if, but instead a raw value. eg line 125 + $rawValue = $value; and 136: if ( ! isset($data[$fieldName]) || $rawValue !== null) { sorry I don't have time to write a pr with tests
admin added the Bug label 2026-01-22 15:02:03 +01:00
admin closed this issue 2026-01-22 15:02:05 +01:00
Author
Owner

@Ocramius commented on GitHub (Aug 24, 2016):

since arrayType->convertToPHPValue returns [] when null, resulting in a leak from the wrong left joined table.

Seems like an issue with the array type, rather than with the ORM itself?

@Ocramius commented on GitHub (Aug 24, 2016): > since arrayType->convertToPHPValue returns [] when null, resulting in a leak from the wrong left joined table. Seems like an issue with the array type, rather than with the ORM itself?
Author
Owner

@w3sami commented on GitHub (Aug 24, 2016):

SimpleObjectHydrator is the file with the problem, type is ok imo. Same
issue is with eg json array type. Hydrator compares with type converted
version not raw value.
For me it makes sense that null is empty array for array type.

On Aug 24, 2016 8:23 PM, "Marco Pivetta" notifications@github.com wrote:

since arrayType->convertToPHPValue returns [] when null, resulting in a
leak from the wrong left joined table.

Seems like an issue with the array type, rather than with the ORM itself?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/5989#issuecomment-242143695,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADiuoZhEIsq1rNG-ucjKzXaAhE9JTgyQks5qjH31gaJpZM4Jr3Ns
.

@w3sami commented on GitHub (Aug 24, 2016): SimpleObjectHydrator is the file with the problem, type is ok imo. Same issue is with eg json array type. Hydrator compares with type converted version not raw value. For me it makes sense that null is empty array for array type. On Aug 24, 2016 8:23 PM, "Marco Pivetta" notifications@github.com wrote: > since arrayType->convertToPHPValue returns [] when null, resulting in a > leak from the wrong left joined table. > > Seems like an issue with the array type, rather than with the ORM itself? > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > https://github.com/doctrine/doctrine2/issues/5989#issuecomment-242143695, > or mute the thread > https://github.com/notifications/unsubscribe-auth/ADiuoZhEIsq1rNG-ucjKzXaAhE9JTgyQks5qjH31gaJpZM4Jr3Ns > .
Author
Owner

@w3sami commented on GitHub (Aug 29, 2016):

bumb! this is actually a quite serious bug, as it renders all our entities with joined inheritance + (json/)array type useless!!

@w3sami commented on GitHub (Aug 29, 2016): bumb! this is actually a quite serious bug, as it renders all our entities with joined inheritance + (json/)array type useless!!
Author
Owner

@Ocramius commented on GitHub (Sep 7, 2016):

The fix in #6004 seems good, besides minor cleanup needed :-)

@Ocramius commented on GitHub (Sep 7, 2016): The fix in #6004 seems good, besides minor cleanup needed :-)
Author
Owner

@Ocramius commented on GitHub (Sep 8, 2016):

Fixed in #6004, thanks @w3sami and @cvuorinen!

@Ocramius commented on GitHub (Sep 8, 2016): Fixed in #6004, thanks @w3sami and @cvuorinen!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5229