Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114221 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56483 invoked from network); 27 Apr 2021 23:34:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Apr 2021 23:34:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1860C1804BD for ; Tue, 27 Apr 2021 16:39:02 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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:39:01 -0700 (PDT) Received: by mail-ot1-f52.google.com with SMTP id n32-20020a9d1ea30000b02902a53d6ad4bdso1875600otn.3 for ; Tue, 27 Apr 2021 16:39:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=985OYvYVNJ24WRU1DT8XeBScpzMUyzlU3S1sCNjvpsw=; b=qRxZiWxYR+Yqc/fNXcQ/66p3eR4Lvqxmw7QNd4C8oDU3nlWZ2dDQxE5rNUj3blX1UP okWq1jFi8lWquyw9yiFX9itl4l0KNt38FR3H0mv/Mnp9dDl2OUW3PUTnwYuBgSqwhPBj m94LEl8SbsEugYkXo089r0DUr0Q/b6nQpgGO0EgdLJamNQoZfZ7uinyIz8BtL/TK/JTP U8OAhYVIqMpzmBUpNzokOA+523BaupsFEphDe/l366oIxa8l2t8+yHh5vLrx/590QFrF aNg5OXz4jiW7k/G/MHB0HpQcM+LkyVi4MQjrJd57gf2alxW4IX66Oygms7WrWjD4mblz R0UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=985OYvYVNJ24WRU1DT8XeBScpzMUyzlU3S1sCNjvpsw=; b=F7aAPxRDbO0jwaYUyhpVnd+ylsGAVo5yBm2p8o4vff5zv2cAp9jl7ROzShKDnRxEQl BDRhSLN8C+5WKM3uAsyfZggo6Kd6CAxnK9lBTca+b2Uw6Jh+Brtg6bZVhrlSC/hNvNVs niit83UAJsoLwwtuKJe96fxYjJhO4u2soe9mUHF1YX8nYCM6IX41tE4LZqdDpJeD0NXY nXKTGtIQpdXjMXF/ecKDQ8nDKDZUJZ+uZS0+oefx1EKwmTxGSD6Vs4Ob8m9rQQzVteAz rmEJ/DjT5EuaksXKR4SlQ9HdALFuRZyX25AMmqnQ6r0ud3+hXVH1+GkMLi1V1Skosol3 OWJQ== X-Gm-Message-State: AOAM532ZZIPgwKYjislshWZXVbrcgNlPO47q9br645Q5DXcHZe2Ca5CK dgGS0UwsnuQivUYOvX2nASiZ3Dg4TEhUz/gT2w0zWJIAdNE= X-Google-Smtp-Source: ABdhPJwBPyqi22zuiBvoQUquzVUQkeVst63732HPQ6fjcoQMF4OPsLchgX86ud70EGHVILNnC8Qm/M9svZRPZs52tHk= X-Received: by 2002:a05:6830:453:: with SMTP id d19mr13675727otc.210.1619566740803; Tue, 27 Apr 2021 16:39:00 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: Date: Tue, 27 Apr 2021 19:38:56 -0400 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000004692de05c0fcc48c" Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: chasepeeler@gmail.com (Chase Peeler) --0000000000004692de05c0fcc48c Content-Type: text/plain; charset="UTF-8" On Tue, Apr 27, 2021 at 7:00 PM Larry Garfield wrote: > 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. > > And I think that is where our approaches differ. You feel that since sealed classes are useful for at least one of the ways classes can be used in PHP, then we should make them available even if that means they end up getting used with the ways that they don't make sense. My feeling is that we shouldn't introduce something that would cause restrictions where they don't make sense just so we can have them where they do. > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > -- Chase Peeler chasepeeler@gmail.com --0000000000004692de05c0fcc48c--