Skip to content

[Yaml] Dumper for enums return !php/const instead of !php/enum #53636

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

Closed
cobyl opened this issue Jan 25, 2024 · 1 comment · Fixed by #53680
Closed

[Yaml] Dumper for enums return !php/const instead of !php/enum #53636

cobyl opened this issue Jan 25, 2024 · 1 comment · Fixed by #53680

Comments

@cobyl
Copy link

cobyl commented Jan 25, 2024

Symfony version(s) affected

7.0.0

Description

Dumper for enums return !php/const instead of !php/enum

How to reproduce

        $dump  = Yaml::dump(Level::Debug, 256);
        var_dump($dump);

gives:

       "!php/const Monolog\Level::Debug"

Possible Solution

The yaml component properly evolves php/const in such situations and returns an enum anyway, but this is confusing.

Replace in Inline.php this line

            case $value instanceof \UnitEnum:
                return sprintf('!php/const %s::%s', $value::class, $value->name);

and corresponding tests

Additional Context

No response

@xabbuh
Copy link
Member

xabbuh commented Jan 30, 2024

Looks like we didn't consider the dumping part when adding support for parsing enums in #46771. Support for enums with the !php/const tag was added before in #40857.

I have openend #53680 to harmonise parsing and dumping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants