Skip to content

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 16, 2026

Q A
Type bug
BC Break yes
Fixed issues #2982 (comment)

Summary

doctrine/collections v1 can't be installed already because of the PHP version compatibility.

doctrine/collections 3.0 adds return types, this PR ensure we have the correct types documented.

  • Collection::add() returns void, we currently return true. BC break will be done in mongodb-odm 3.0
  • The ArrayCollection::matching(): Collection method is more restrictive than Selectable::matching(): ReadableCollection.

@GromNaN GromNaN added this to the 2.16.0 milestone Jan 16, 2026
@GromNaN GromNaN added the Bug label Jan 16, 2026
Comment on lines +802 to +804
if (! $coll instanceof BaseCollection) {
throw new LogicException(sprintf('The matching() method of the backed collection must return an instance of "%s".', BaseCollection::class));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default implementation of PersistableCollection extends the ArrayCollection that has a more specific return type than Selectable::matching(): ReadableCollection
https://github.com/doctrine/collections/blob/a8353e2e0cb9db12ceb87c8e76114bd885b0170f/src/ArrayCollection.php#L386

@GromNaN GromNaN requested review from alcaeus and greg0ire January 19, 2026 10:29
* @param mixed $element The element to add.
* @phpstan-param T $element
*
* @return true The return value is kept for BC reasons, but will be void in doctrine/mongodb-odm 3.0.
Copy link
Member

@greg0ire greg0ire Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might make sense to do a conditional bc break (based on the version of doctrine/collections), as in https://github.com/doctrine/orm/pull/12341/changes#diff-9634c9dcbc64c9326048aaa0df50b1a5dea4214b83b56ccb5ef676bf076841f6

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback.
I would have to put all the methods of the interface in the trait in order to have compatibility with both doctrine/collections 2 and 3.
I wonder if I should extend AbstractLazyCollection instead, and just use a conditional trait for the add method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe yes. I think PersistentCollection 49fb4e4 was introduced 3 years prior to AbstractLazyCollection (doctrine/collections#19)

Although ODM wasn't explicitly mentioned, I think it might have been hinted at in doctrine/orm#882 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've open an issue, I want this PR to get merged without support for doctrine/collections v3:

@GromNaN GromNaN changed the title Prepare compatibility with doctrine/collections 3.0 Compatibility with doctrine/collections 3.0 Jan 21, 2026
"php": "^8.1",
"ext-mongodb": "^1.21 || ^2.0",
"doctrine/collections": "^1.5 || ^2.0",
"doctrine/collections": "^2.1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doctrine/collections 1 is already not compatible with PHP 8, so this changing nothing.

* @param mixed $element The element to add.
* @phpstan-param T $element
*
* @return true The return value is kept for BC reasons, but will be void in doctrine/mongodb-odm 3.0.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback.
I would have to put all the methods of the interface in the trait in order to have compatibility with both doctrine/collections 2 and 3.
I wonder if I should extend AbstractLazyCollection instead, and just use a conditional trait for the add method.

@GromNaN GromNaN changed the title Compatibility with doctrine/collections 3.0 Drop support for doctrine/collections v1 Jan 22, 2026
@GromNaN GromNaN merged commit 85324ee into doctrine:2.16.x Jan 22, 2026
28 checks passed
@GromNaN GromNaN deleted the selectable2 branch January 22, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants