Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118712 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39744 invoked from network); 30 Sep 2022 05:34:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Sep 2022 05:34:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1E5181804AB for ; Thu, 29 Sep 2022 22:34:15 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,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-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 ; Thu, 29 Sep 2022 22:34:14 -0700 (PDT) Received: by mail-qt1-f179.google.com with SMTP id gb14so2088526qtb.3 for ; Thu, 29 Sep 2022 22:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20210112.gappssmtp.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:subject:mime-version:from:from:to:cc:subject:date; bh=YcqFeIRHRjf3oovZhJvL9HPNmF5/psX5quSdNFzY+f4=; b=MZkRa0POhGEw+q0Nxwfnvi2x/OldkbKcIIpOOWkEmXmZqToCBnbDOlpeZUN4c2aSgx 7FDw/KOA4EId+cHe/eFlUkjOyUogOBSPJREI00d8C04RlOeOjlzEK/+CQbSWHOk4NCNq WEct07vFOR8l1X+oa7ISifWlPQ1vFa9Htkv/dWjSVG1Q1K0vUalKwZgSkXFZZiQXdVQa MgTw+fStEA/kCKQPwYOLLHxDetyW7uugB4nDADpS96HERiWtnAsj4l1+f1ANCGYh5E5X 0675McLWFOc0FviFsIo7WzzKrNOEEaWJEuV+aV3zSmQ79zvD5vBFv7MlqLWGGF/PRnG/ QIRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:subject:mime-version:from:x-gm-message-state:from:to:cc :subject:date; bh=YcqFeIRHRjf3oovZhJvL9HPNmF5/psX5quSdNFzY+f4=; b=uprooSVOS64SKa7DHxCVVf9K33ar6nTAh/ro1FlJQQ3z+IzZvylnxhrrYp556BbSGO Kk4A1PTiwMmYUKvuGNlb/L/EU8FTQz/yvv4dwC7OvnuMHSnooADfQmJuHjD4KUbILSmF b+eGgTPR8UhfSsVC8pnBOnQIwsdfiu/IjUANRoGzyhGkCqD2nldawM0ecXKSNrdfgVhC YgnyHJnSq2z2PI9/wGAZ3PyEojAvrE4z9c2jy9yBn7nTLgaJNUf0ygyEpsXxTMV3VH/1 aya4q18rt7lBF5FInPb+WLa/HaiS6Ao521kpaCs5B0PE2Asejede/TzWr7XcC52PXYXN Hjag== X-Gm-Message-State: ACrzQf31AnEk2NSvHFt5lkWWU/uZLiiewMM7az0QsFPEyLedr6TmORbD wPDK7+v1NHho56IApXQtAshdHQ== X-Google-Smtp-Source: AMsMyM4tcSHo29llgw35m13zvXc1waJQvKbU3ta6KvBd2KJVkLjWyb1lorHjoo22+lYuvh43G3mrjA== X-Received: by 2002:ac8:7f06:0:b0:35c:f532:3346 with SMTP id f6-20020ac87f06000000b0035cf5323346mr5389642qtk.316.1664516053545; Thu, 29 Sep 2022 22:34:13 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id i13-20020a05620a248d00b006cbe3be300esm1637080qkn.12.2022.09.29.22.34.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Sep 2022 22:34:12 -0700 (PDT) X-Google-Original-From: MKS Archive Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) In-Reply-To: <67365E50-D383-4B5F-B8E9-95AC2E136223@getmailspring.com> Date: Fri, 30 Sep 2022 01:34:10 -0400 Cc: "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: <0173F88D-D26F-4C97-9219-074380946BC3@gmail.com> References: <67365E50-D383-4B5F-B8E9-95AC2E136223@getmailspring.com> To: Mohammad Amin Chitgarha X-Mailer: Apple Mail (2.3608.120.23.2.7) Subject: Re: [PHP-DEV] Specify abstract parent methods for traits From: mike@newclarity.net (MKS Archive) > On Sep 18, 2022, at 7:51 AM, Mohammad Amin Chitgarha = wrote: >=20 > Hi. >=20 > Currently, it's possible that, inside a trait's function, use the = parent method of a class using the trait. This way, not only it's = implicitly supposed the trait is used in a class having a parent, but = also the parent class has such a method. It doesn't seem to be a good = practice, as stated in the answers of this question = (https://softwareengineering.stackexchange.com/questions/371067/should-a-t= rait-refer-to-parent-methods). > Also, it's almost impossible to override a parent method (using the = same signature) using a trait. This is useful if you have to inherit = multiple classes from a base class, but also override one (or more) of = the base methods with a common functionality provided by a trait. > There are some workarounds to these problems (specially talking about = the later one), but they have their own disadvantages: > Define a trait function with the same signature but a different name = and use it. The main disadvantage is that it's a different method, and = is not polymorphic. > Do (1), include the trait in the derived class(es), then override the = parent method in all derived classes and manually call the trait = function. Not perfect because you have to copy the same code for all = derived classes. >=20 > Stick with parent:: in the trait function. Implicit and not good (e.g. = static analyzers and IDEs cannot help). >=20 > Change the parent class to use traits. This is not always possible, as = it might be someone else's code. How often have you (or anyone else?) found a need to inherit someone = else's class and then need to override one of their methods via a trait? = A need that you felt you could not easily work around in some other = reasonable way? If yes, could you please give some examples? -Mike