Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114156 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38169 invoked from network); 25 Apr 2021 19:18:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Apr 2021 19:18:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8E96E1804DC for ; Sun, 25 Apr 2021 12:22:40 -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 out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (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 ; Sun, 25 Apr 2021 12:22:39 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4908A5C00C1 for ; Sun, 25 Apr 2021 15:22:39 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Sun, 25 Apr 2021 15:22:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding: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=POOFMgvaS3Vjuoawm19ctMOpA50EJXNbooTbwyv0C zA=; b=toAII/616/aZKmb3m6VxVMLTXmHsPLb1tm6BC9bWOCFZZDPTDb4E285ct tNTHlVhWX05IOKaSf2zHXkx5YBX+A+vryI1QvlinVUFOWpOykPFKbmtM3anaA8zX zY/hIYutXl0ewDGnx8OLxaO9j6t7SlyvZ/qzoT6GuYMl2PehvdT4PzPxZnLLcQ03 OpeMtDqMqZzhjW13vY4dQwVI26E6Lw5sdvlb7OawtewRTGUE26C4pTlc8eu2AcMP AyzpVM+MxG5oJVmZS6esK5mA7mS66z0c/lWqSr4MWEgYyqT3KmklpJU79AApf6j7 0H2vZ+AHBowBZ9RLLGYJbNaA1RxUg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdduiedgudeflecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeff jeelfeejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id F13A53A02D2; Sun, 25 Apr 2021 15:22:38 -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> <0BF84585-DDC3-4B25-BFD2-D8B916D135EE@newclarity.net> Date: Sun, 25 Apr 2021 14:22:07 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC][Draft] Sealed Classes From: larry@garfieldtech.com ("Larry Garfield") Stitching together 2 replies to minimize thread noise... On Sun, Apr 25, 2021, at 11:58 AM, Micha=C5=82 Marcin Brzuchalski wrote:= > Speaking of Attributes I prefer not to use an Attribute for any partic= ular > language feature which expects input arguments to be a valid class or > interface name for two reasons: first because there is no effective wa= y to > restrict input string to be a valid class or interface name and second= that > it'd require passing strings which means in most cases passing class o= r > interface name with magic ::class constant read. >=20 > Cheers, > Micha=C5=82 Marcin Brzuchalski That's actually a pretty solid argument against attributes here, honestl= y. Consider me convinced, and now in favor of "final class Foo permits = Bar, Baz". :-) On Sun, Apr 25, 2021, at 12:52 PM, David Gebler wrote: > Still, all these problems are solved to the same degree if you add a > #[Sealed] attribute to a class which has no functional impact. You hav= e > sufficiently indicated to any user that extending this class is not a > designed feature and may cause backwards-incompatible breaks with futu= re > releases - in a way that both a programmer and IDE can reason about, w= hich > in PHP's context is what matters. Attributes arguably even have a grea= ter > qualitative advantage that they can be applied right down as far as > individual method parameters. >=20 > In Java the idea of final and sealed classes makes more sense, since w= e > actually to some extent need the compiler to be able to reason about t= hese > types and can gain optimization and code generation benefits from its = being > able to do so. PHP's concept of typing and implementation of type chec= king > as an interpreted language is completely different. >=20 > I wonder, if final and sealed as language constructs really offer the > guarantees about intent and safety their advocates say they do, why ar= e > they not the default? Why can no one point me to a language where I ha= ve to > write something like >=20 > extendable class Foo permits all { .... } >=20 > (and there are people who would be in favour of making inheritability = this > explicit, but I'm not one of them) >=20 > It's one thing as an author of code to say "I only intended and suppor= t > this finite set of use-cases", it's quite another to say "and you shou= ld be > impeded from proceeding with any legitimate use-case I didn't imagine = or > foresee" >=20 > In practice, the only thing I've ever seen this achieve is to create > difficulties, while the claimed benefits can be adequately (and better= ) > achieved through existing patterns like annotations, interfaces and DI= . Part of the challenge here, i think, is that PHP, like most classic OOP = languages, uses the same syntax for two different things. One is for pr= oduct types (an int combined with a string together in a single struct),= the other is bound values in closures (aka, methods in service objects)= . That's arguably by design in classic OOP, and arguably a design flow = in classic OOP. :-) I can think of no reason at all to make a service object's class sealed.= For those, yes, you shouldn't forbid custom extension, and frankly I u= sually discourage the use of private variables, too, for the same reason= . For product types that are part of the domain, however, there are defini= tely use cases where you want a defined finite list of possible variants= . The Distance and Maybe examples upthread, for instance. That's not a= lways the case, but there are definitely cases for them. --Larry Garfield