Skip to content

Stabilize enum interface error handling and tests#1954

Merged
GromNaN merged 1 commit intomongodb:v2.xfrom
GromNaN:fix/enum-interface-error-order
Mar 18, 2026
Merged

Stabilize enum interface error handling and tests#1954
GromNaN merged 1 commit intomongodb:v2.xfrom
GromNaN:fix/enum-interface-error-order

Conversation

@GromNaN
Copy link
Copy Markdown
Member

@GromNaN GromNaN commented Mar 13, 2026

Follow-up #1953 (comment)

@GromNaN GromNaN requested a review from a team as a code owner March 13, 2026 17:31
@GromNaN GromNaN requested review from alcaeus and Copilot and removed request for a team March 13, 2026 17:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Stabilizes the fatal error message emitted when PHP enums attempt to implement MongoDB\BSON\Persistable, making it consistent across PHP versions despite changes in interface_gets_implemented handler invocation order.

Changes:

  • Adjust Unserializable’s interface_gets_implemented handler to prefer reporting Persistable in the fatal error when applicable.
  • Remove Persistable’s custom interface_gets_implemented handler (enum rejection is centralized in Unserializable).
  • Update PHPT expectations to assert a stable Persistable-specific fatal error message.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tests/bson/bson-enum_error-003.phpt Updates expected fatal error output to consistently reference MongoDB\BSON\Persistable.
tests/bson/bson-enum_error-004.phpt Same as above, for backed enums.
src/BSON/Unserializable.c Special-cases the enum-implementation fatal to prefer Persistable when the enum implements it.
src/BSON/Persistable.c Removes redundant enum-implementation handler; relies on Unserializable handler.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/BSON/Unserializable.c
Comment on lines +29 to +33
/* Persistable extends Unserializable, so this handler may be called for
* Persistable enums; prefer Persistable in the fatal message when applicable. */
if (interface == php_phongo_unserializable_ce && php_phongo_persistable_ce && instanceof_function(class_type, php_phongo_persistable_ce)) {
error_interface = php_phongo_persistable_ce;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Still not convinced to keep this part. That's the Unserializable behavior that is not supported.

Copy link
Copy Markdown
Member Author

@GromNaN GromNaN Mar 13, 2026

Choose a reason for hiding this comment

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

If Unserializable::bsonUnserialize() was static, then it could return an enum case and this would not be an issue.

Copy link
Copy Markdown
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

LGTM. We can revisit the discussion around Unserializable, although I think that codecs are the better variant to deal with BSON data than the Persistable solution.

@GromNaN GromNaN merged commit ab67e04 into mongodb:v2.x Mar 18, 2026
47 checks passed
@GromNaN GromNaN deleted the fix/enum-interface-error-order branch March 18, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants