fix: Serialize native PHP enums with name and value instead of opaque 'Object' string#2038
Open
jarstelfox wants to merge 3 commits intogetsentry:masterfrom
Open
fix: Serialize native PHP enums with name and value instead of opaque 'Object' string#2038jarstelfox wants to merge 3 commits intogetsentry:masterfrom
jarstelfox wants to merge 3 commits intogetsentry:masterfrom
Conversation
…opaque 'Object' string Enums were caught by the generic `is_object` branch in `serializeRecursively()`, causing them to render as `Object ClassName` when `serializeAllObjects` was enabled. This adds an early-return for `UnitEnum` before the object block and enhances the output to include the backing value for `BackedEnum` instances. Fixes getsentry#2037 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
stayallive
requested changes
Mar 26, 2026
Collaborator
stayallive
left a comment
There was a problem hiding this comment.
Overal this looks good, thanks for taking the time.
One change is that we would like to not potentially clobber any custom serializers by moving the if statement down a bit. Can you make this change?
Comment on lines
+119
to
+121
| if ($value instanceof \UnitEnum) { | ||
| return $this->serializeValue($value); | ||
| } |
Collaborator
There was a problem hiding this comment.
I think we should move this down to where we check for the DateTimeInterface. This way you can still provide your own serializer if you want to and only if there is none we shall default to serializing it ourselves (which is a sensible change in itself).
…erializer priority Moves the enum early-return inside the is_object block, after the class serializers loop, so custom serializers registered via class_serializers still take precedence over the default enum serialization. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
jarstelfox
commented
Mar 26, 2026
Contributor
Author
jarstelfox
left a comment
There was a problem hiding this comment.
Good call, moved the UnitEnum check inside the is_object block after the class serializers loop so custom serializers still take precedence. Updated and pushed!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Object ClassNameinstead of showing their actual enum case and valueUnitEnuminserializeRecursively()before the generic object block, so enums are handled correctly regardless ofserializeAllObjectssettingBackedEnumoutput to include the backing value:Enum ClassName::CASE(value)Fixes #2037
Test plan
testBackedEnumsIncludeValue— verifies backed enum output includes the valuetestEnumsAreNotSerializedAsObjects— regression test withserializeAllObjectsenabled/disabledtestBackedEnumsAreNotSerializedAsObjects— same for backed enums🤖 Generated with Claude Code