Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123413 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 1EC1F1A009C for ; Thu, 23 May 2024 13:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1716469482; bh=zV0rHwJ8Jcj3zvNvokhL3odXQG0pv9+ooRdIRqqzQJA=; h=In-Reply-To:References:Date:From:To:Subject:From; b=Nvd3FurTRt7a+NHLDBlzp5YV62IZL1dXYJCctkNu/aeQD3of2dILIrzZTyZN/AUHs sYs780ZSfnSwKDDq8zgHNNSg2kVgud0BvKIaJHxbqw1s76pCJYLAZl+A3DEEcBN4wE +hMYXA3NWoy6NfznMT7aRjODmalixqOKsFQZiz0/9TwQVNn/ZkfgwljGdYeRs2XdOl dI+SIa+etZuQ7sQCNvJDEZI1XEjEBC1r29CNAXiV0DGckQGfayZcGjHNHNAaZFpe9w /r0A5TidL7xjPSFk5JKVrgmEqVsuMskTlnfLGMO3Tp+WcqXaWB/Cuo4J/Fr4yB0vjC CxOl1f3BG4PnQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AC14218065F for ; Thu, 23 May 2024 13:04:40 +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_MISSING,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (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, 23 May 2024 13:04:40 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 6684218000F0 for ; Thu, 23 May 2024 09:03:42 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Thu, 23 May 2024 09:03:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1716469422; x= 1716555822; bh=NFeHLOkwuf5X6M4dIiv0r1fX0bAu1Gfc4y5d/E3FGX8=; b=H MMtVgAWNlbjSJbVY3gYjdFJhAySt3mj/LvZojVcrV40L1ynl+uV0uyOSwwwjupYT hNAm9ez0ny/UF0R9em740erDKfLm8cElo+zu+264ifhczJ34+E1Ir4K+aS+kNbWB 7NetZO9RKRKQp/P8XwPJpr4G+GkZDZ2OqFilBUoaBRDTCTzrt3qZcA84HM/UUwTo lz5kRS7rc5DSldHf9gaRoxiiqDiaJoQJo1Rza+utTogQgkIvfXbHZqLfrQ+ju2cw xWJrS2uGHh4iN+IO7f1GYlJdBiTvDICQq3986NzgzwQQKY8AgDcCs0blcSay7c8W KlrOAUvtXxVXbKYKv/mLg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1716469422; x=1716555822; bh=NFeHLOkwuf5X6M4dIiv0r1fX0bAu 1Gfc4y5d/E3FGX8=; b=RD06lgaIrillhfRRo/ls2ow07GB74rD82ItbT062M4OJ JrnxdJLy1Mc6lzTSWrtNd6JbxgXFAKptAYigqDfiX4t0fjHW9MmEr5c96IPINwEO NVOZyPPyDJLITBbU3JB4VZGaSFcdGfu6LIc5NKdcMVZNq/V2nGxzH3VweOeBIcX+ o9JQo+pZDGkJestzAibbml6ihoaQLrbDV12cNYO+ATQl4hrRUBToL2HLYEqKNnIq 6e7O4pFNS4yzmGEXyOi3pR6z5KP2oLjNQ1R9bJFDYWr1m6uEUfEFDQ13CVMRLQOZ ly42nkgvTCesq0fmD5vgVXHfsxcvBrf8uYJBUo4PRQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeiiedgheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6E3F11700093; Thu, 23 May 2024 09:03:41 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-480-g515a2f54a-fm-20240515.001-g515a2f54 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: <99c30f5d-e2f3-4027-a8fc-b3b9c71fb6d1@scriptfusion.com> <1286eed1-c35e-40ec-a6f0-84926c99c911@app.fastmail.com> <3cac0454-ceb2-449a-8b9a-1fac3f866a9c@scriptfusion.com> <9c763cee-6524-4423-b95e-6bfff4763d2e@app.fastmail.com> Date: Thu, 23 May 2024 08:03:21 -0500 To: "php internals" Subject: Re: [PHP-DEV] [Discussion] Implicitly backed enums Content-Type: text/plain From: larry@garfieldtech.com ("Larry Garfield") On Thu, May 23, 2024, at 1:35 AM, Robert Landers wrote: > For what it's worth, the biggest downside to this decision is in > upgrading old/legacy projects to use enums. Most of the time, you want > to convert a const to an enum, and that also usually means it will be > a backed enum. Since there's no way to cast a backed enum to a > string/int, you have to instead add ->value (I really don't understand > the difference; casting would have been much more elegant); this > almost always results in lots of hidden runtime errors. At the last > couple of places, after seeing the damage the conversion could do, > doing this conversion was simply off-limits. Maybe by now, there is > some reliable tooling to handle this automatically... I haven't > looked. The point remains that it is a strange decision to use > `->value` but not allow `(string)` or `(int)` or allow even > implementing it yourself. Union types are the correct solution here: function move(string $direction, Player $player) { ... } becomes function move (Direction|string $direction, Player $player) { if (is_string($direction)) { $direction = Direction::from($direction); } // We now have a normalized enum to work with. } The only catch there is inheritance, where it works fine if you jut expand the implementers/children first, then the interface/parent. Then you can remove the string option at some point in the future, going the other way (interface/parent, then implementer/child). --Larry Garfield