[PR #8356] fix(persistent-collection): check "association" is not nullable before using it as an array #10943

Closed
opened 2026-01-22 16:09:11 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/8356

State: closed
Merged: No


Hi,

Today I've faced an issue with Doctrine 2.7 and https://github.com/KnpLabs/DoctrineBehaviors when configuring the parameter doctrine_behaviors_translatable_fetch_mode to LAZY (see KnpDoctrineBehaviors Translatable configuration):

image

By using xdebug, I found it was coming from the method PersistentCollection#get() which try to use $this->association when it is equal to null:
2020-11-30_16-36

There are already some methods that check if $this->association !== null:

So I've applied the same patch on all other methods that use $this->association without checking its value.

WDYT? Thanks!

**Original Pull Request:** https://github.com/doctrine/orm/pull/8356 **State:** closed **Merged:** No --- Hi, Today I've faced an issue with Doctrine 2.7 and https://github.com/KnpLabs/DoctrineBehaviors when configuring the parameter `doctrine_behaviors_translatable_fetch_mode` to `LAZY` (see [KnpDoctrineBehaviors Translatable configuration](https://github.com/KnpLabs/DoctrineBehaviors/blob/master/docs/translatable.md#configuration)): ![image](https://user-images.githubusercontent.com/2103975/100630231-92d4e180-332a-11eb-820e-55a583000b34.png) By using xdebug, I found it was coming from the method `PersistentCollection#get()` which try to use `$this->association` when it is equal to `null`: ![2020-11-30_16-36](https://user-images.githubusercontent.com/2103975/100630318-b0a24680-332a-11eb-8f2d-910450d9dae8.png) There are already some methods that check if `$this->association !== null`: - `changed`: https://github.com/doctrine/orm/blob/e0eb82a/lib/Doctrine/ORM/PersistentCollection.php#L294 - `remove`: https://github.com/doctrine/orm/blob/e0eb82a/lib/Doctrine/ORM/PersistentCollection.php#L357 - `removeElement`: https://github.com/doctrine/orm/blob/e0eb82a/lib/Doctrine/ORM/PersistentCollection.php#L380 - `count`: https://github.com/doctrine/orm/blob/e0eb82a/lib/Doctrine/ORM/PersistentCollection.php#L443 So I've applied the same patch on all other methods that use `$this->association` without checking its value. WDYT? Thanks!
admin added the pull-request label 2026-01-22 16:09:11 +01:00
admin closed this issue 2026-01-22 16:09:11 +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#10943