Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114220 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54938 invoked from network); 27 Apr 2021 23:28:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Apr 2021 23:28:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BCD871804BD for ; Tue, 27 Apr 2021 16:32:53 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 27 Apr 2021 16:32:53 -0700 (PDT) Received: by mail-qt1-f173.google.com with SMTP id 1so45514843qtb.0 for ; Tue, 27 Apr 2021 16:32:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=vvj7UaoMGHxtq2wPToyiWCinyzyZkDtpEAXXIDfMLQ4=; b=qEop7o12ddIXlRQ8Hb1jfTywoz8Ivu8TMM0OXFxXj5l/xm45jxsogKmH0+wmUhzJKo Hs2caxHFSMCSTLUa03TeSozi/51DYIaZzcb80QkafnHVlcnPQkENrCouWe0qRWo0oVIm ltHfsidqQ6UebaqtwczyAG2g0mZHujR1uLGnjVwnpEuLMurV6SAxgSEDj4yRGzehFMoI 9ZX13/djfUHVi7I+cNHTnbeWIFgfF9XqzjTUR94KipFmfEgsByeXZqIl9KZQ0kLdfp6p XKQj/lSsHm7MjqXLPrA3B5IKRyjjfyX1AX5j3tCWqD8U4pJE2fC2td58WeT38bZ4ysEs emIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=vvj7UaoMGHxtq2wPToyiWCinyzyZkDtpEAXXIDfMLQ4=; b=QGiGa229NwoyDiU+O12qhcclQo1HO18z2gXjlVEVhTY9RtTQlu6e2ojKLhWC8N+nbq Oe4RaF3PlvmRxsOh6Yp/M6OTJMJpNrsaHgkz9+AZw47hkXL5DRh/Lb83SSMCyiwNG9bR xQbF6wRzK049JyUhgZCNBoBbPeQK4sPCocigWSSA5Ml68CsxIV0rd/d8OHkSooYMhT+8 kWfBZJMM/NKzzuXzrJ79p+CGNdnYckMUIo/TZkBKCZdLGCuwqxnXa+BfqIm+xFvQMcg6 j0+bySn5nmyyVbG1+zehEL9GLGhek7JrmsKMo65ouAmeUFvdxY+exod8LY33LdX6pIRF 6zhQ== X-Gm-Message-State: AOAM5318EBOGQDHl6EcGjsg15zOBW0TCE42cIxfU7//Pv7vbOn4tj0X4 bUoZrT5ynz9BL8lzDPWm97xtrqfANpzLZA== X-Google-Smtp-Source: ABdhPJyUslq9KV6ruNraNGtO7XziFXrslKZuooxO7QCX3YRr76NjfP/ce++fBBP0gMkhsjvO5KBSyA== X-Received: by 2002:ac8:57c6:: with SMTP id w6mr23698953qta.309.1619566372513; Tue, 27 Apr 2021 16:32:52 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id o23sm971655qtq.28.2021.04.27.16.32.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Apr 2021 16:32:51 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.6\)) In-Reply-To: Date: Tue, 27 Apr 2021 19:32:50 -0400 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <13488B36-4864-4831-96A4-74FDA1E3B210@newclarity.net> 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> To: Larry Garfield X-Mailer: Apple Mail (2.3608.120.23.2.6) Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: mike@newclarity.net (Mike Schinkel) > On Apr 27, 2021, at 7:00 PM, Larry Garfield = wrote: >=20 > On Tue, Apr 27, 2021, at 5:48 PM, David Gebler wrote: >> On Tue, Apr 27, 2021 at 11:23 PM Larry Garfield = >> wrote: >>=20 >> The two options to prevent such errors are: >>>=20 >>> 1. Sealed classes. >>> 2. Extend Enums into ADTs. >>>=20 >>=20 >> 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. >>=20 >> class Perhaps extends Maybe implements OperatesOnTheValueInterface { = ... } >=20 > 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. >=20 > 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. >=20 > 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. But, are we really, stuck? =20 You successfully introduced enumerations. Why not also data types and = control flow types? Just asking for a "friend." > 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. >=20 > See also: This thread. :-) >=20 > 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. >=20 > --Larry Garfield >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >=20 -Mike=