Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110255 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40814 invoked from network); 22 May 2020 17:47:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 May 2020 17:47:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2F68F1804F6 for ; Fri, 22 May 2020 09:26:12 -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_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) (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 ; Fri, 22 May 2020 09:26:11 -0700 (PDT) Received: by mail-il1-f174.google.com with SMTP id y17so9033371ilg.0 for ; Fri, 22 May 2020 09:26:11 -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=0dsbiJRwbuqapfo73BCy14R8VCWQzNHROmS3TsfdEkA=; b=p8LPunGsWCbBmXY4NHae+rkKb8S5YFA4GwVrwuMvsSkInYDQR04xkHbPuaSoQ1Og/l jcRvHwLvVSwP2TA3GVfX9NxEFhwt1vPy5mQurQ9EOlnu8ZxPQK46NBZHEOUH8RHUc5nX usxn4CUn3I48CjExN39f1Ug6rlSR2IhFzRrYxwQLwMC0fFWQtIi8k339LukW2Xii4Pv0 eET1lywpAYHhwSrEFwI8scKPh2iLyRCtOD0jV1KDTsdA6dwJ2xK39xjAf3vO1l43C1fZ igyPc9E0rMtsFB8/D0wBWyciENztLEdgYRRKboNP/JD8tPV5OCvYb1drrdFtkFs/69FG QzKw== 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=0dsbiJRwbuqapfo73BCy14R8VCWQzNHROmS3TsfdEkA=; b=ScFGLVQsGGIA2ZBdBLoxsdQFZ81yZ9FV7+fDsGpUdWi4JOv6LS3MmHTmRfRMhL2rWD KTBV7klPqTkb/TqUudYC2aBt0cKHmQey80bggsU8PT7RpM4I1YIw1AHWQ01J7SmV5+5i MR92aqcm4Hn5CUQkSRpwIbAtu4MDCpKR0BLy8HxOPNEU4X0PQTBcMoQZpg6js9X5D4e3 Sv+roQxMYmlr7spjsSUeZQK1+BSAqTG+nlPFG8Yohrp7JbfEcLKDoFH7Ru7DLa9Fhg29 Wn2KXwcCwMCm9zuOCbY6ktlc1HtSGf/OnWwqZ+v8d8ffK6/GCPdni44AhLe78AGlwqtA iovw== X-Gm-Message-State: AOAM530pwM12A2cZdl6I9MSD6cfPAp859nJ8pbqwJQwcF+w3Lw7fQRo1 VbE5K5hNLjXCfxUgEgTRwTRU+UDlLIlSk0Zvj+ncmCJs3Ss= X-Google-Smtp-Source: ABdhPJz/G5JUqUP+WyAVZ4IzKxPdVx6dnDIX6YFeDsFPPy/y/NSyrt5ASToVWiPfP/K7g0yVccSYyT54i/QB3gD6Efo= X-Received: by 2002:a05:6e02:f4e:: with SMTP id y14mr14287435ilj.165.1590164769762; Fri, 22 May 2020 09:26:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 22 May 2020 18:25:58 +0200 Message-ID: To: =?UTF-8?Q?Pedro_Magalh=C3=A3es?= Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000003c735d05a63f16d1" Subject: Re: [PHP-DEV] [RFC] [Discussion] Remove inappropriate inheritance signature checks on private methods From: ocramius@gmail.com (Marco Pivetta) --0000000000003c735d05a63f16d1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey Pedro, On Fri, May 22, 2020 at 5:43 PM Pedro Magalh=C3=A3es wrot= e: > 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 private > 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 and > the child's method is non-static, or vice-versa > - When a method has the same name as a parent's concrete private method a= nd > the child's method is abstract > > I have 2 open issues on the RFC that I would like to hear some opinions o= n. > - 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 th= e > BC break. > - Whether or not to make an exception to this rule for magic methods. Giv= en > that this is widely to restrict object instantiation and cloning, it coul= d > make sense to still allow the use on those cases. However, I think that t= he > similar effect that can be achieved with "final protected function" would > 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 P= R > ( > 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 type, 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 good idea. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --0000000000003c735d05a63f16d1--