Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120579 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72115 invoked from network); 14 Jun 2023 22:20:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jun 2023 22:20:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E5D511804F2 for ; Wed, 14 Jun 2023 15:20:42 -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, T_SCC_BODY_TEXT_LINE 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-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 14 Jun 2023 15:20:42 -0700 (PDT) Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2b1b30445cfso18405971fa.1 for ; Wed, 14 Jun 2023 15:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686781241; x=1689373241; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OiXNYhrXf9BgvO/LxqaVxwLhhbfRJnOV0On9QoixXHI=; b=CCms2HHcHJYs+jVq1vX3ujL+yAgPpXdNCZcKMYgqrF46Coj8R8cL1uQnQKlbRNr7T6 n1LEAHu6vAM9Puf/7jHKLcDumC7WnTxdJjlsCaGJ0283P3BkgB0UKleW4TeixsxD3uME nbu4xDfuTwEVGMdVQeMUjLYu/fKcAm/Sp1gmlOV2VZ024u47FpivtrSLJK0ybI7RM0S6 QWblKP6TvlgBA1t2rBY+M+goLwggC/e3Yemzhsa4zP+YfcerwV9OqgnkqEFBNbZPOjFS dYMZH7iguV6sKuDG+1zSclY/dYqjP8uykuOkD8ZLwFjP67exQtgtE0sCboxq3jb87PDZ bkcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686781241; x=1689373241; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OiXNYhrXf9BgvO/LxqaVxwLhhbfRJnOV0On9QoixXHI=; b=SHHVCAtakrKpmFsHqQiIatYzjK4a8e09mPoKKANhu722ZqH8bxgtr9W3wJqW3qAc/X bPjtF6dwOwvVVMVUtVx1XnxcxoSIap0bUFcpxgKuZVTfVkrDcv/e005WrRG+wNq2IvFZ Gt7WsuFBiS1IsO2qoazwypnW/EowWAD6E+qMLfMk44V4/VbJRXPvJHUjt9wF7vT2v8QK aJ/jUIwUFaAZg4BdSLG2d5CImCqayT+vW1u+SGjje4ZC99+3CXTtJ3OlA40Di1r0eQzk CvGU+ym/ftbjtH9pf8FBKiBb/MhwNiHTsP3k3aNWhCalWIX11ZGpL4NCpsB+/D+QBxI+ zDaA== X-Gm-Message-State: AC+VfDx9Jorsf2EXw0q0TE43166aCFORjPlEwvUAEiY5+Sfz+j4t4gDH Islw9TD3HbNnJGJHvtcA9JOG/0SLMSwZfJcXs37nfOVf5An5+g== X-Google-Smtp-Source: ACHHUZ5EZlPVeAujfaXPQD4kJOF+Wz+dZ/L+SsalXI0jMdstSkMbov1+tLKHCV5sGONOCVbDy0Nl80KLtR8f1qzrWiE= X-Received: by 2002:a05:651c:22a:b0:2af:2441:f709 with SMTP id z10-20020a05651c022a00b002af2441f709mr7525738ljn.29.1686781240291; Wed, 14 Jun 2023 15:20:40 -0700 (PDT) MIME-Version: 1.0 References: <648A1621.1070306@adviesenzo.nl> In-Reply-To: <648A1621.1070306@adviesenzo.nl> Date: Wed, 14 Jun 2023 19:20:04 -0300 Message-ID: To: Juliette Reinders Folmer Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000a4382805fe1e5c51" Subject: Re: [PHP-DEV] Unexpected behaviour when using Traits with final methods From: ericklima.comp@gmail.com (Erick de Azevedo Lima) --000000000000a4382805fe1e5c51 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi. The point is: traits are not inheritance. It's assisted copy-and-paste. When you use a trait, it's like you typed those methods yourself. But if you type them in the class that's using the trait, you throw away the method definition from the trait and use the one from the class. You can see here what the final keyword on your trait is intended for: https://3v4l.org/loOqQ#v8.2.7 I hope I was able to help. Best regards, Erick Em qua., 14 de jun. de 2023 =C3=A0s 16:34, Juliette Reinders Folmer < php-internals_nospam@adviesenzo.nl> escreveu: > Hi all, > > I'm running into something which peaked my curiousity due to its > unexpected behaviour, so I'm writing to the list in the hopes of finding > out whether this is by design, a bug or an oversight which should be > fixed (via an RFC?). > > > The precedence order is that members from the current class override > Trait methods, which in turn override inherited methods. > Source: > > https://www.php.net/manual/en/language.oop5.traits.php#language.oop5.trai= ts.precedence > > If one would want to prevent the "current class" from being able to > override a trait method, I would expect that the `final` keyword would > be able to do this, just like it would when a method is inherited from a > parent class. > > Unfortunately, that does not seem to work and it appears that the > current class can freely override final methods from a trait: > > ``` > trait Foo { > final protected function bar() { > echo 'Foo'; > } > } > > class FooBar { > use Foo; > > public function __construct() { > $this->bar(); > } > > protected function bar() { > echo 'FooBar'; > } > } > > new FooBar(); // Prints "FooBar". > ``` > https://3v4l.org/hlirb > > Which brings me to my second point: in PHP 8.0 the use of the `final` > keyword with `private` methods has been turned into a `warning` via this > RFC: https://wiki.php.net/rfc/inheritance_private_methods > > ... but the "current class" has access to `private` methods inherited > from a trait, so I would expect `final private` methods in traits to be > exempt from that warning, but turns out that that will still throw the > warning: https://3v4l.org/Vb0S2 > > Is there anyone who can shed some light on this behaviour ? > > Smile, > Juliette > --000000000000a4382805fe1e5c51--