You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Proposal]: Adjust handling of EnumEntry::toString() for backed enums #2107
Right now, EnumEntry::toString() calls will always return a name for any given enum, while it's most of the time a perfect fit, but when you have \BackedEnum, you may expect to get the value aligned to the name, not the name itself.
oh I see what you mean, hmm lets take one step back and maybe think about purpose of toString() method.
Right now, method toString() is being used in different contexts:
by EntryNormalizers (which I guess took you here)
by printers, like to_output()
plus some minor places like Row::hash()
But you are right, with BackedEnum it might make sense in certain places to use value, instead of name. However I believe current approach is correct one.
Let me explain, why:
<?phpenum Color: int
{
case Red = 0;
case Orange = 1;
case Yellow = 2;
case Green = 3;
case Blue = 4;
case Indigo = 5;
case Violet = 6;
case Purple = 7;
case Pink = 8;
case Brown = 9;
case Gray = 10;
}
So if we print values from toString() method we are pretty much getting in console under column name color just integers when we use to_output().
I think that EntryNormalizers should use EnumEntry::value() : ?\UnitEnum and be configurable, which means there should be a possibility to configure entry normalizer to:
always use name for all entries
always use value for all entries
use name for only specific entries
use value for only specific entries
by default always use name
This would need to be a similar configuration to date/time/datetime formats that we pass to normalizers.
Activity
norberttech commentedon Dec 28, 2025
oh I see what you mean, hmm lets take one step back and maybe think about purpose of toString() method.
Right now, method toString() is being used in different contexts:
plus some minor places like Row::hash()
But you are right, with BackedEnum it might make sense in certain places to use value, instead of name. However I believe current approach is correct one.
Let me explain, why:
So if we print values from toString() method we are pretty much getting in console under column name
colorjust integers when we useto_output().I think that EntryNormalizers should use
EnumEntry::value() : ?\UnitEnumand be configurable, which means there should be a possibility to configure entry normalizer to:This would need to be a similar configuration to date/time/datetime formats that we pass to normalizers.