Re: [RFC] [Discussion] Stringable Enums
| From: | Bob Weinand | Date: | Thu, 04 Dec 2025 20:44:42 +0000 |
| Subject: | Re: [RFC] [Discussion] Stringable Enums | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129554@lists.php.net to get a copy of this message | ||
Good point Derick,
On 4.12.2025 14:36:14, Derick Rethans wrote:
On Thu, 4 Dec 2025, Tim Düsterhus wrote:Daniel, if you want to improve the magic method situation here, I'd much rather encourage you to add __debugInfo() than anything else. (Also fwiw I think __toString() should never have existed in the first place; but that's a wholly different topic.) BobHi Am 2025-12-04 09:01, schrieb Rowan Tommins [IMSoP]:I agree, and also: We usually have aAnd 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.__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