Re: [RFC] [Discussion] Stringable Enums

From: Date: Thu, 04 Dec 2025 13:36:14 +0000
Subject: Re: [RFC] [Discussion] Stringable Enums
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-129546@lists.php.net to get a copy of this message
On Thu, 4 Dec 2025, Tim Düsterhus wrote: > Hi > > Am 2025-12-04 09:01, schrieb Rowan Tommins [IMSoP]: > > > And is it even a good name for those methods? In the date-time > > package, for instance, it would be better named toEnglishName() or > > getFullEnglishName(), as its docblock explicitly says. In the > > framework code, it seems to be used for a property called > > $displayValue, so the obvious name for the method would be > > getDisplayValue(). > > I fundamentally disagree with the proposal for reasons similar to those that > Rowan mentioned. More specifically, I consider implementing > __toString() to > be a mistake, unless it is for a debug representation. I agree, and also: We usually have a __debugInfo() method for debugging purposes. Instead of allowing __toString() to be added, I think I would rather see __debugInfo() being allowed. It must continue to be not possible to treat enums as strings. cheers, Derick

« previous php.internals (#129546) next »