Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112320 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51608 invoked from network); 30 Nov 2020 15:52:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Nov 2020 15:52:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EB6DE1804A8 for ; Mon, 30 Nov 2020 07:19:20 -0800 (PST) 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-Virus: No X-Envelope-From: Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 ; Mon, 30 Nov 2020 07:19:20 -0800 (PST) Received: by mail-lj1-f180.google.com with SMTP id t22so18512759ljk.0 for ; Mon, 30 Nov 2020 07:19:20 -0800 (PST) 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=1+cstJKnSeeVZbu61F1fjKIF86uVx0Qv/en/iAfcPFc=; b=R02pXH3KMwXdBaRanQ3FfLODDq5n1fhMyg5V66eGNWfp8edqFvK3quUsxffmcvKsaJ QvwqOhSDfBKVfQH8D8dd82Zt748DKWgYccw9d0J8Q2ztA5YCHB6uGojsnDeCXeroiQC0 ot2Gm92cCRCymXn68NyJsL47jsIxtkAyjhYavarpvm/ld6wvzp50B/vHkL9Ws3EUwnWe IfHlodMTFzm4mRTx9lKWQbdcr5TPp8DCrbyC2JMfv3kJqZHRB3d79fP2D+WydigpcloU UDUBRIhTroz9Sf8sexwK+yNIw9+tM4GXXkU1/OTvffRzjBqSrT05dTZrKZ0NfjjZMZ6F Jb+g== 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=1+cstJKnSeeVZbu61F1fjKIF86uVx0Qv/en/iAfcPFc=; b=hj89vd9bPeoFKrmad6sPYzCNlRN0g08ybCTpDKXa8HRlzsxa4jk3kvUqkcVtG2Iaoh 0hSU0scULpOfXBn9Kca9m2CGHLKwrEMkNXe9iflEv5VB7WAcz4+8IWfgchNdj8ta98Ps UwsUFgVCg9V/HV+ThZ2JcCae1aTLDvTsOYWUtMbsW0/mB4Rg4fSvs70QaQQvZvzOn1oJ org8J4f6TqMUDoomDiKDLQyBI/hOK1OcK/t5WSNtr4MlF4wHqznde7cbkXhhqXd4p7KL d2kpLTKK2FwC9DTNNPehzBVS1HilmSWQHyuyVlJrQugIkSjYFZZjHB24S+yH/BCq/5Rt wBgw== X-Gm-Message-State: AOAM532OOx0TuNkS9jocKMV6umH+FS05bVmpiDOcDfOk74KJmQOSjiki Pi6F2Y1idgNU9DPpddBxTx23FjyId+B6OGfpATA= X-Google-Smtp-Source: ABdhPJxWStzFG23a0FD3kFR5eMX/XY+tmiIYc9Ui66SRmR50HDq3aKps+Hu5n697pipO8+XhbpIivZphjJoDKVmwfSY= X-Received: by 2002:a2e:bc15:: with SMTP id b21mr8888437ljf.350.1606749558125; Mon, 30 Nov 2020 07:19:18 -0800 (PST) MIME-Version: 1.0 References: <265e9893-f82c-39f2-3323-2854b246658d@processus.org> In-Reply-To: <265e9893-f82c-39f2-3323-2854b246658d@processus.org> Date: Mon, 30 Nov 2020 16:19:01 +0100 Message-ID: To: "Pierre R." Cc: David Rodrigues , PHP Internals Content-Type: multipart/alternative; boundary="000000000000a7b82005b5548820" Subject: Re: [PHP-DEV] Traits "implements" support From: nikita.ppv@gmail.com (Nikita Popov) --000000000000a7b82005b5548820 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Nov 26, 2020 at 5:53 PM Pierre R. wrote: > Le 26/11/2020 =C3=A0 17:50, David Rodrigues a =C3=A9crit : > > Hello! > > > > Now with PHP 8, traits supports abstract functions that should be > > implemented by the class that uses this trait. > > > > So is it now possible that traits could have support to implements too? > So > > when class uses this trait, it will be an implementation of X interface > and > > will have to implement methods based on it. > > > > interface A { > > public function x(); > > } > > > > trait B implements A { > > public function y() { $this->x(); } > > // public function x() still not implemented. > > } > > > > class Z { // impliticy implements A interface due to B trait. > > use B; > > public function x() {} // required! > > } > > > > > > Atenciosamente, > > David Rodrigues > > > Hello, > > I'd love this too, but I'm not sure what would be the static code > validation behavior, knowing that you can rename methods of traits when > using them in a class: should the trait method not be validated ? Should > the final class be validated after the trait has been used, meaning that > if a method name change, the final class must re-implement it ? > Common misconception: It's not possible to rename methods of traits, you can only create aliases. That said, there's still an issue in that you might resolve a conflict in favor of an identically named method that uses a different signature. Note that Hack uses a "require implements" syntax instead, which makes it clear that the interface needs to be implemented by the using class: https://docs.hhvm.com/hack/classes/trait-and-interface-requirements Regards, Nikita --000000000000a7b82005b5548820--