Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110279 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91350 invoked from network); 26 May 2020 15:54:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 May 2020 15:54:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C6F1E1804C3 for ; Tue, 26 May 2020 07:34:19 -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=-0.9 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS20857 149.210.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from outbound2.mail.transip.nl (outbound2.mail.transip.nl [149.210.149.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 26 May 2020 07:34:18 -0700 (PDT) Received: from submission14.mail.transip.nl (unknown [10.103.8.165]) by outbound2.mail.transip.nl (Postfix) with ESMTP id 49Wc0n1pzJzYd1s for ; Tue, 26 May 2020 16:34:17 +0200 (CEST) Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by submission14.mail.transip.nl (Postfix) with ESMTPA id 49Wc0j6Ym6z2SSJN for ; Tue, 26 May 2020 16:34:13 +0200 (CEST) Received: by mail-wr1-f48.google.com with SMTP id l11so20675088wru.0 for ; Tue, 26 May 2020 07:34:13 -0700 (PDT) X-Gm-Message-State: AOAM5339af0JH21dKKxUxz9TzUilJ5Ej3MD50hpNEfWJ166sAruPtbt8 re1YEEzCIub+Jl5Fz0Y2nGK+vvGQQNC6GzfoRNc= X-Google-Smtp-Source: ABdhPJwOQnaeJrUf1rBjSnDLuMNdquEuUaW6bEZs2n1CEe+JDqI2SAKVDv9+TvpbM4Bm3dNZ9K3f95nuHA2RjN8PY9Q= X-Received: by 2002:a5d:4484:: with SMTP id j4mr20023107wrq.325.1590503652821; Tue, 26 May 2020 07:34:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 26 May 2020 15:34:01 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Marco Pivetta Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000003d902b05a68dfd95" X-Scanned-By: ClueGetter at submission14.mail.transip.nl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=transip-a; d=pmmaga.net; t=1590503655; h=from:subject:to:cc: references:in-reply-to:date:mime-version:content-type; bh=3Wr3tczWpdWzvhw/QfTMeQWpG9mnO447pNnkbcQ6X6E=; b=sJVYrQVgq4Ja2OEuybJv7titTG7A1wjXvBF9tH0rJBWc2/0D1Z6qJX14l7VNcsW0sVqttO GVkTeYhe1GGawYNaxtutcptiJmQDYuqk3gzcL1gHxG/VFc8IFM5TSzvdL7jBj83hYH+iNT S0Zysg1+fGaIHl4NWni2qfqLzTnF1lsWwfG++dhI6TC7bL3Xvtj1rTzI0L/flKvNOnAQ91 S8WpSSE3tpKNgar4VysuU8K/HExCYdhiNVtHvaKPgaSfzoU+rnTvzlCCZw95L7rnv+w++e ENuwHoQgofwY8fSFqZC+V+4Kl9hOC8BwGiJflV1Mfx3Y6zDhwWUAhDoFSeevsA== X-Report-Abuse-To: abuse@transip.nl Subject: Re: [PHP-DEV] [RFC] [Discussion] Remove inappropriate inheritance signature checks on private methods From: mail@pmmaga.net (=?UTF-8?Q?Pedro_Magalh=C3=A3es?=) --0000000000003d902b05a68dfd95 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Marco, Thanks for the feedback. About the sealed type example, it is true that `final protected` wouldn't achieve the same thing. But as an attempt to provide an alternative design, wouldn't an union type of the desired children be a better choice? I can see some usefulness in it but IMHO, it is supported by a broken behavior, it doesn't make sense to talk about private symbol overrides. That shouldn't be a thing. With that said, I don't think the RFC has to be all or nothing, but we would leave an exception behind. About lifting the restriction only to magic methods, I don't really like that approach. Anything that makes them more special feels like a step in the wrong direction. If we were to lift that restriction, I would say that it should be lifted for any method, leaving the RFC to deal only with the static and abstract cases. About the serialization example, I think that goal is equally possible to achieve with final protected. Regards, Pedro On Fri, May 22, 2020 at 5:25 PM Marco Pivetta wrote: > Hey Pedro, > > On Fri, May 22, 2020 at 5:43 PM Pedro Magalh=C3=A3es wr= ote: > >> Hi internals, >> >> I want to put up for discussion an RFC ( >> https://wiki.php.net/rfc/inheritance_private_methods) that proposes to >> remove some inappropriate signature checks that are still done on privat= e >> methods. Namely, those checks are: >> >> - When a method has the same name as a parent's final private method >> - When a method has the same name as a parent's static private method an= d >> the child's method is non-static, or vice-versa >> - When a method has the same name as a parent's concrete private method >> and >> the child's method is abstract >> >> I have 2 open issues on the RFC that I would like to hear some opinions >> on. >> - Whether or not to issue a compiler warning whenever "final private >> function" is used, to alert the user that it will not achieve what that >> construct is currently used for. The disadvantage of introducing it is t= he >> BC break. >> - Whether or not to make an exception to this rule for magic methods. >> Given >> that this is widely to restrict object instantiation and cloning, it cou= ld >> make sense to still allow the use on those cases. However, I think that >> the >> similar effect that can be achieved with "final protected function" woul= d >> cover most of the cases. And if we open up that exception for magic >> methods, for the sake of clarity maybe we should just keep the "final >> private" behavior on all methods and just change the static and the >> abstract behaviors. Some discussion on this subject can be found on the >> PR ( >> https://github.com/php/php-src/pull/5401) for this RFC. >> > > Overall, this RFC breaks some design capabilities that are within the > language, specifically around `__`-prefixed methods in the language. > > For instance, I design (on purpose) sealed types as following: > > ```php > abstract class Email > { > final private function __construct() {} > public static function business(): Business { > return new Business(); > } > public static function personal(): Personal { > return new Personal(); > } > } > > final class Business extends Email {} > final class Personal extends Email {} > ``` > > The above approach guarantees that no further subtypes exist for `Email`, > other than `Business` or `Personal`, effectively forming a safe union typ= e, > which can only be broken by reflection. > > In addition to that, I often prevent serialization of types that are not > intended to be serialized (when not final): > > ```php > abstract class InMemorySecret > { > final private function __sleep() {} > } > ``` > > Effectively, the `final` modifier applies to `private` symbols too, and > prevents child classes from deviating from imposed design constraints. > > It is **intentional** for `private` symbol overrides to not compile in > these cases. > > Both of the above examples only apply to special/magic methods: I can see > and understand that for custom methods this RFC may be valid, and adding = a > further refinement to lift the restriction only on custom methods is a go= od > idea. > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > > --0000000000003d902b05a68dfd95--