Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114219 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51727 invoked from network); 27 Apr 2021 22:56:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Apr 2021 22:56:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DAABC1804DB for ; Tue, 27 Apr 2021 16:00:43 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 27 Apr 2021 16:00:43 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 223DE5C0154 for ; Tue, 27 Apr 2021 19:00:43 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Tue, 27 Apr 2021 19:00:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=4NSWQ3 etYTyWpdCZc8/5wT+fJk04zHP/f4Lby/KUw4U=; b=GFBQFn7MWB6l28SkWwVySl pRhMVqMyjfjs9b7+0IBfz0+ATBH3XpOpfL8riV/NS1uODETapL8Xm0E/pVmHYIz0 /PWgHJrj7bfOkgUYv4McuV5hOOK5Haz3a2QzGi854BszAihBz0anRUqto8tCtZvS pi0asemHi/73bgxkvIkDNEyIRqiPq/QTHZaFjzZAFxoviWoZkW57ypnP2qbFWAyb +OUkmZGHmA8SFjftEz9+oeJW/4tPmXQ2J49t6lJKJMal5IolgTk+vrO7SOVwO3j9 l6xM2RfKza1Lpn6Qzwj6Ps1B9yMKyd6lbl8sdizKAuM/f5cn2RWYU48KjsUOKEdQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddvuddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id D453E3A02D2; Tue, 27 Apr 2021 19:00:42 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-403-gbc3c488b23-fm-20210419.005-gbc3c488b Mime-Version: 1.0 Message-ID: In-Reply-To: References: <5b9f1500-615a-48f1-815f-1d48b327ef90@processus.org> <179049b1475.11134368b213512.254739612773841999@void.tn> <722ed544-69e3-3be4-f828-185914617228@processus.org> <51fffd88-03c7-463d-a6d7-94c086cb5893@www.fastmail.com> Date: Tue, 27 Apr 2021 18:00:22 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: larry@garfieldtech.com ("Larry Garfield") On Tue, Apr 27, 2021, at 5:48 PM, David Gebler wrote: > On Tue, Apr 27, 2021 at 11:23 PM Larry Garfield > wrote: > > The two options to prevent such errors are: > > > > 1. Sealed classes. > > 2. Extend Enums into ADTs. > > > > Unless I've misunderstood your example, there is a third option which quite > possibly prevents the error in a nicer, easier to reason about, more > flexible pattern. > > class Perhaps extends Maybe implements OperatesOnTheValueInterface { ... } If we were dealing with a service object in classic OOP (viz, OOP based on classes), then yes, turning the function into a method and using polymorphism would be the correct answer, rather than RTTI. However! Classic OOP design patterns are not all that PHP supports, and that's a good thing. The "class" construct, for better or worse, is the syntax for logic objects, value objects, data objects, and control flow objects (such as Maybe, Either, etc.), plus assorted other patterns that are not part of the classic OOP canon. But they're still good and useful patterns, and often a better model than classic OOP "polymorph all the things" approaches. If we were designing PHP from scratch today, I'd argue for having separate language constructs for funcy-syntax-closures (which is what service objects are), product types (structs, value objects, all the same thing), and control flow types. Many newer languages do differentiate those better. That's not where we are, though, so we're stuck with class being the uber-syntax for anything even slightly interesting from a type perspective. So be it, but it does lead to ample confusion about which use case you're talking about, especially when not everyone is familiar with all of the different, distinct use cases. See also: This thread. :-) Sealed classes are... not really useful at all for service object use cases. They are useful for product type and control flow type use cases. --Larry Garfield