Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118650 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22974 invoked from network); 18 Sep 2022 11:51:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Sep 2022 11:51:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8C4B4180210 for ; Sun, 18 Sep 2022 04:51:24 -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.6 required=5.0 tests=BAYES_50,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-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 ; Sun, 18 Sep 2022 04:51:21 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id r7so1877378wrm.2 for ; Sun, 18 Sep 2022 04:51:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:message-id:to:from:date:from:to:cc:subject :date; bh=vktegfe68n4MmNMu7Tdzpxzm2NE/iA6/5Keu3fKcCjc=; b=JwucFTog0ondyeptpNJZPycyvPlYJ6FadRQmQWAGN6MaYr4VnA7FFbutFSJ89ZPqGZ Ef8qnw/cWkZZ00uEf9VwHv9gDvsSiN0zqpLd5nf18Jnrqmommirv9WdR3Mv59JTOr/m2 16sRBEO7n8B1A++Y4dZvdd6yZjSXUIVTx+1X2i41df6lUKKec44js4eCQcSeDw+NU6jP E/4GtG9vn7Hp/obiPZgsa1E8iSJTJC6dkDgarvCV91zTz1TWQfq4EQkwqNr6EYEmld3G i2VRiaYWnDjExCRxDvIr3vMgQkk6z1RQZ4oYZiBmciF0g2urYvULgMKxnJsD2oZQD3aI nf1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:subject:message-id:to:from:date:x-gm-message-state :from:to:cc:subject:date; bh=vktegfe68n4MmNMu7Tdzpxzm2NE/iA6/5Keu3fKcCjc=; b=LH+WtrY+CLadLZXABLAC4Sf0o8vFXLIPgVRWOfpkP6PcWp/BZeEHfzwnmxOxnLq7jv 3RXnbnF6hKE2reFKECwpIttXsnImf3d8pnvnnDlN4h2tWdUvCWcrXD/F1fVXOYKgjedI 6DPnYWwgn33QLSuYOixKZWcVm4lded64uZiRpcNf3pfSPRobbgwJCLNu1JWbpMt/hFsb vPC2ocaxSdj5uaS8zacBpdd2P8Iallb3rDxFCYg/fWQ48eBkUPOIqKg/+FLj8Ro/s1hY FpdzfjD1gZBsjfsHQZgEkp6ro1a4QvmD5hrJHAbuzjAeRZ+9N0967EEKtj0TSz5ONqOS 25LQ== X-Gm-Message-State: ACrzQf3lB31xp5JsiiG8hhasofXnViuTG46uvlokrEylK2KV25YsSrwP KTwvTJvL25gUSbdAHcltzhE70u6noRAQDAMKQWU= X-Google-Smtp-Source: AMsMyM4gIchLWVX44SCRtq2VxIuB2faxaAjxslr6XaPGr1Sh1kQ/qKpqoG1N9htg20LXnO9kWFnyFA== X-Received: by 2002:a5d:5a14:0:b0:22a:25be:7f69 with SMTP id bq20-20020a5d5a14000000b0022a25be7f69mr7744642wrb.662.1663501879256; Sun, 18 Sep 2022 04:51:19 -0700 (PDT) Received: from machitgarha ([5.117.70.75]) by smtp.gmail.com with ESMTPSA id 9-20020a05600c22c900b003b476cabf1csm9614458wmg.26.2022.09.18.04.51.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Sep 2022 04:51:18 -0700 (PDT) Date: Sun, 18 Sep 2022 16:21:02 +0430 To: "=?utf-8?Q?internals=40lists.php.net?=" Message-ID: <67365E50-D383-4B5F-B8E9-95AC2E136223@getmailspring.com> X-Mailer: Mailspring MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="63270626_5305b475_c87" Subject: Specify abstract parent methods for traits From: machitgarhaa@gmail.com (Mohammad Amin Chitgarha) --63270626_5305b475_c87 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi. 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 sup= posed the trait is used in a class having a parent, but also the parent c= lass has such a method. It doesn't seem to be a good practice, as stated = in the answers of this question (https://softwareengineering.stackexchang= e.com/questions/371067/should-a-trait-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 me= thods 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 par= ent method in all derived classes and manually call the trait function. N= ot perfect because you have to copy the same code for all derived classes= . Stick with parent:: in the trait function. Implicit and not good (e.g. st= atic analyzers and IDEs cannot help). Change the parent class to use traits. This is not always possible, as it= might be someone else's code. Ignore this please: copy and paste the method all over the place. It's also not possible to use things like insteadof or as when including = the trait. Here, I want to propose the concept of explicitly declaring the parent me= thod. The way to achieve this is to use attributes for trait functions, e= .g. =23=5BOverride=5D. It has the advantage of not requiring the redeclaration of the parent met= hod as abstract. However, it should be not allowed to use as clause when = including the trait function, as it's against the definition of overridin= g a method (i.e. it must have the same name and visibility). Another method is using a new parent specifier (i.e. abstract parent publ= ic function =E2=80=A6), and is more (=3F) consistent with the current beh= aviour. However, it requires duplicating the parent method signature. There could be methods using insteadof or as, but they has nothing to do = with the trait itself, and doesn't fix the problem of implicit declaratio= n of the parent method in the trait. Thanks, Mohammad Amin Chitgarha. --63270626_5305b475_c87--