Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129542 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id E9FFB1A00BC for ; Thu, 4 Dec 2025 09:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764841074; bh=BA+g9ssj2rSK1xlLo0ZJsIblE0aHSen6dVhdQHmJq1M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KBsKWzRTpy8VUjBuKDOI63rG+2uKGZcBsX35zil71YvModSNbt7zqHXRAdRLEjer6 7+YnxxA/zzfXSot3LAkPH3ykQng3c393yCz/cVWoUOfqJgh3zLoob+sFbAjX46FLPn jhOW4+Mtzy7qeIYazwT76ZKFizavYRS9bJNJKs0lcqCb0IJ5aGzrX3KaMzvGfloAuA yZjkrEmJOYszqRklkwV5p8LprAn2g27DlyzRT2XvSCiMipmVE6Dho6YE2jwVxOi52E m0T15Qa6ix0Bd/5hndlSjUnCQ7713eqHSs0RBAmJpRqkUcHOxOkREMqsdazbwLDeJB WT9Bc+kaFhdKg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6752B180080 for ; Thu, 4 Dec 2025 09:37:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 4 Dec 2025 09:37:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1764841066; bh=kt+i/suUC4CO9FANdiiwx+RAAZFHMJHsZ6xPJ01l4WA=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=NW7V3MjV8jHLHpKwwCgxOs5VYUzlyOi8mkbuKinMU5uDlq5R/AYmdYmpP7rsQ/1Py /VRHoj9W6GEYJxzo4ZeTU2Cmp5xdofWjTvTXbncM+KXFIrPXjG2gzMkgTZQ6zTI+U2 S5QJO+2VnNtsW9rqt7246t/bZsaera8YcbnZS7u2pN8Y12hRvzBJFONyh0+j8jRyyx k/31jXZs8TeowB4KLKpzvo6pZXPK4b9FTSPBnV16bC71HDMY5PwAy+yKJvIeuYszfk Z276R1+Fnb5dKVx3AUhPSHwgE538zQuGsHU4hMBN1npylzR1EDN5tyCr6dH+70BaRS 7317jEdTUeASQ== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 04 Dec 2025 10:37:46 +0100 To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Subject: Re: [PHP-DEV] [RFC] [Discussion] Stringable Enums In-Reply-To: <3D90E174-23F2-4B90-B881-20A0AD30CF0C@rwec.co.uk> References: <3D90E174-23F2-4B90-B881-20A0AD30CF0C@rwec.co.uk> Message-ID: <31ed0152483193e85ca3a9eebc5e6d14@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-12-04 09:01, schrieb Rowan Tommins [IMSoP]: > My first instinct was that this was dragging up a discussion we've had > lots of times, but your examples make clear that you are *not* just > talking about converting enums to their backing value. > > On the other hand, that does make me wonder: in what way is > (string)$foo clearer than $foo->toString() for those use cases? In my > experience, it just makes the functionality less discoverable - people > don't think to try (string)$exception or (string)$simpleXmlNode, so > miss that those have specific behaviour. > > 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. There rarely is a single (or primary), obvious and parameter-less string representation for a given object. There might be one for enums, since they can't hold state, but as the previous RFCs indicated, folks generally expect it to just be the enum's value which then just encourages folks to treat enums as “fancy strings” or “fancy class constants” rather a proper data type unto itself even more than they already do, where it's `->value` all the time. And with the planned enhancements of enums into full tagged unions, I'd also rather not make decisions now that we might regret later when actually extending enums to tagged unions. Best regards Tim Düsterhus