Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement enum json serialization #896

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dont-know-php
Copy link

@dont-know-php dont-know-php commented Oct 29, 2024

Hi team, this is a small PR fixing enum serialization.

Prerequisites

zend.exception_ignore_args must be disabled.

Description

PHP doesn't support Pure Enum json serialization: https://www.php.net/manual/en/language.enumerations.serialization.php

If a Pure Enum is serialized to JSON, an error will be thrown.

We will get an serialization error, for example, if we want to write json serialized error trace with arguments into log, because some package classes/methods use enum in arguments.

There are two possible solutions:

  1. Using Backed Enum
  2. Implement JsonSerializable interface. I chose this option because the package uses Pure Enums.

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.

1 participant