Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125047 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 qa.php.net (Postfix) with ESMTPS id 3145C1A00BD for ; Mon, 19 Aug 2024 15:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724080329; bh=c21gWK/SoS+owvDQsBbBu7G5iaP86l0hYz/MKzupnjs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gHXEpdTvM+LxIIZF0aWLNid8kRO0JYq0Um2+js/A8Gsv5PKpY5QR/qpfCPpjnL5vi s0Bbwv/rkl1YKfwPNaa9wIHMSWSFSGojBbyM7RAhAEfgpEeyspQlpq3lsaCIW9TcpZ tIELenuCZUxU1YbyMGcTJ27T4aRrl+oqz7Y7jHh/WzCJHAOWrUHib+w3NnRfdeWoYe smdBtrRXw7fyjnZnvaypobcW5A+EWwNTkzWawHT2RjNCfyUtqch1h+u3z2jUxqfD+d wptjpctyRYEpFTZ2/gdP97IAkzPCrenh5uk2oG1VNQ3eqUjUedpGJdBV785VlOVAcm qn2TyNCCjvY7w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0B3FD180042 for ; Mon, 19 Aug 2024 15:12:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) 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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 ; Mon, 19 Aug 2024 15:12:08 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4280c55e488so23345805e9.0 for ; Mon, 19 Aug 2024 08:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; t=1724080218; x=1724685018; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=C6eFLPXJgCl9CZzOhxDytQ5S7wialOd6fHGriLsZvm8=; b=VTVie2fVB/v+Q2o/zmj89JNi02eP2cLsoYetldmM1g4UF9pnySiax4niZcffitKECN KZNZKVB3Ng8aZfZ99uS3G1hSZbE0V82O9CTIUunoDboKfv1y/wtMbGp2EZN1g7ZuBz54 rB4rbUai6ep0zYWc/2mqHokIHsPQISfUr90F0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724080218; x=1724685018; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C6eFLPXJgCl9CZzOhxDytQ5S7wialOd6fHGriLsZvm8=; b=stF8XuGJF7mXK4XZqLsRipKh+lVk+md1ICtmMzXKJ+08tMbB6QBoT3wdBdsiClNnfV B0iZQuK7w+KuI9Xg/XMqx/nztWGI6XLdOFnC3MyDSZxIl1lcCBgcZh4SgWw3f9YzAtFO uoG4kYTPFl6E1KqbpZnl7u8nxsskz3Yn+TgzGxs1ddKkpMeh4wWsr0SWRZ5ysldWk8m7 Vdvs5zKKqHO1HxC5zFRA1AHCDaaLf3MNAz2fCWsioJO1g7DM3uMdQFaRlw9PXe3YQzTh K3DELTB77eDkWeXRYDuZc+Nvgv6E4uptQyVHxtlGYhHiYDJ3JwzaEvXmAYXYKrpbdp1Q 4Pag== X-Gm-Message-State: AOJu0Ywfg2E5AvHbpob0Xt+lonis0UEh7e5og+YTjhj8QvB+KV+ZW3Fh 6WDX+KD4H3T27EE3Jyf+/2yhsxXiQS2dRvd7kiefp1QgywInimIDAxwGYCWgt5kkxkf1ODYlfN8 1/HpGPl1gmSoefg/aa+Ewzpo6Z+mw1uCXB5lqdG/TzRXpcnh4 X-Google-Smtp-Source: AGHT+IGuX8O9NOaA7P+0bMCKvapzQM5zl/HEcixVhEmHHJYqhYTKSR5buxLfZvOB8BASGohVzfOIlRMHrqeRIn1Yb8M= X-Received: by 2002:a05:600c:5124:b0:426:6327:5a16 with SMTP id 5b1f17b1804b1-429eda33161mr61096045e9.18.1724080218274; Mon, 19 Aug 2024 08:10:18 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <2A3FFD56-789F-4ECF-8E9F-A84804E484D1@getmailspring.com> In-Reply-To: <2A3FFD56-789F-4ECF-8E9F-A84804E484D1@getmailspring.com> Date: Mon, 19 Aug 2024 09:10:06 -0600 Message-ID: Subject: Re: [PHP-DEV] String enums & __toString() To: John Coggeshall Cc: "internals@lists.php.net" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: levi.morrison@datadoghq.com (Levi Morrison) On Fri, Aug 16, 2024 at 1:43=E2=80=AFPM John Coggeshall wrote: > > Hey all, > > I poked around a bit in the Enum RFCs and I could find (maybe I missed) w= hat's up with this: > > enum Foo:string implements \Stringable > { > case FOO =3D 'bar'; > > public function __toString() { > return $this->value; > } > } > > PHP Fatal error: Enum Foo cannot include magic method __toString > > It seems to me that when the enum is a string it is entirely reasonable = to expect __toString() to work here and support the \Stringable interface= . > > Is there a reason I'm missing as to why this is problematic in the engine= that's been documented somewhere, or is this an oversight we can look at c= orrecting? > > John As others have said, there are definite objections to auto-implementing string conversions. I think that opt-in string conversions are sufficiently different that you would have a shot at an RFC passing. No guarantees about that, of course!