Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120576 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 61703 invoked from network); 14 Jun 2023 19:34:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jun 2023 19:34:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0B1B8180209 for ; Wed, 14 Jun 2023 12:34:00 -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=3.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL,STOX_BOUND_090909_B, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS36483 23.83.208.0/21 X-Spam-Virus: No X-Envelope-From: Received: from insect.birch.relay.mailchannels.net (insect.birch.relay.mailchannels.net [23.83.209.93]) (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 ; Wed, 14 Jun 2023 12:33:57 -0700 (PDT) X-Sender-Id: a2hosting|x-authuser|juliette@adviesenzo.nl Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 49E7C761D5D for ; Wed, 14 Jun 2023 19:33:56 +0000 (UTC) Received: from nl1-ss105.a2hosting.com (unknown [127.0.0.6]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id 2C8A6761CCD for ; Wed, 14 Jun 2023 19:33:55 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686771235; a=rsa-sha256; cv=none; b=5F7phILIK/sHn2T0qTQ+7DVW0HyYmDdeKl0Ndj2Lfx0yInMvpV98U7VeejkFPf3wwikHhw AxgJYMrX2QAKdvu4tg2MkJviiviCCwf9IxPibDlTg5cKS8rsL4rD5mao2LS9SBArnGvOb1 QmLmH55q49MHlmIXlE9pGmILfSgeLQ7Yo83IHDDa2BAY+QDAB9fB4QOsTm4jIS+VGyuWUB HH2sF5VAANBdcgI70fmH/tEXUM40h3MAfF3Oze2oIr12xDOiF5QQpdJfNyjQZYtmVsfrbS fd8BJKe+EuUDNnW7EmG33kEi0QeLE610VvqNKTmy4YHe5oDxydTfuAWI2Im+fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686771235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: dkim-signature; bh=IVs+WgHESfmMw/9IEuXe0mgWdap/yb0NH6674C8daZM=; b=ktEy+13unIRTxZ/6YUsh1/JL9Z+fKntifnABye8HJV+/PLhPW/QpdszJEoR/QMMKOImcW6 hhp6l5sEgZJAawVxqpzNJxZbVd1nsnaelkgsORUTRJzR5r4Ko/Y13tvE0D89yh0Bix754d We0dt1K5IaadTd7pYMNhz2BCkcpvfBwtjBF9rh13ycnVmP392obqK8kesR1UiDzZMLmIen DA5SFY2ABFAab4lDNpdTst5jrn1f9fU+LglkeclW0l/uOaU4/kOsEra8BXyIfGnx5cJHpm XnpbPVu/D/jTRGjkYZja0+FhUpJ2eTpeh6qZKnHJdnzgn25ew07DSVgcqcejFw== ARC-Authentication-Results: i=1; rspamd-6c69b8658d-gbwvs; auth=pass smtp.auth=a2hosting smtp.mailfrom=php-internals_nospam@adviesenzo.nl X-Sender-Id: a2hosting|x-authuser|juliette@adviesenzo.nl X-MC-Relay: Neutral X-MailChannels-SenderId: a2hosting|x-authuser|juliette@adviesenzo.nl X-MailChannels-Auth-Id: a2hosting X-Stretch-Whimsical: 6b8b98e566a9c41b_1686771235754_4169541197 X-MC-Loop-Signature: 1686771235754:2170087677 X-MC-Ingress-Time: 1686771235754 Received: from nl1-ss105.a2hosting.com (nl1-ss105.a2hosting.com [85.187.142.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.116.217.201 (trex/6.9.1); Wed, 14 Jun 2023 19:33:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=adviesenzo.nl; s=default; h=Content-Type:MIME-Version:Date:Message-ID: Subject:From:To:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Q/4UMqi3gtuLMojkq7n6lkUjMkhvA3OJFn6PaOkTWWM=; b=ogNH4ipecJSaaALPUKtlO9uK53 +OmwaWjcR2uNnfRYUpnUX+8+5wcNsj+ZcJtH5ljl27sOoMgN6M6ijTTJ76M6DwBcAIcn0nZPviRyJ zVeBpTMXE0Wi1n6tdnEJ3UsIRh3+KGtQF+V1YIRepD4pViI+c1Wb8QVXtjeWITj5hQNg=; Received: from [143.178.154.86] (port=58960 helo=[192.168.1.104]) by nl1-ss105.a2hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1q9WFe-00Atr7-2s for internals@lists.php.net; Wed, 14 Jun 2023 21:33:53 +0200 To: PHP Internals List Message-ID: <648A1621.1070306@adviesenzo.nl> Date: Wed, 14 Jun 2023 21:33:53 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------010903050108050109040507" X-AuthUser: juliette@adviesenzo.nl Subject: Unexpected behaviour when using Traits with final methods From: php-internals_nospam@adviesenzo.nl (Juliette Reinders Folmer) --------------010903050108050109040507 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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.traits.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 --------------010903050108050109040507--