Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101949 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 801 invoked from network); 1 Mar 2018 23:04:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Mar 2018 23:04:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.173 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.128.173 mail-wr0-f173.google.com Received: from [209.85.128.173] ([209.85.128.173:45881] helo=mail-wr0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AB/62-16517-9F6889A5 for ; Thu, 01 Mar 2018 18:04:25 -0500 Received: by mail-wr0-f173.google.com with SMTP id p104so8252692wrc.12 for ; Thu, 01 Mar 2018 15:04:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=qKN1PglFlgOofJiNr4Baz1hTaTbHaIGFueL4oCIzYa8=; b=h1q0JTUvnNhTHXeqfpIkKtzXCwAarL0v/itUnkHNhWZrH6N2Whkm7fXEJJNSExRmOj a9kcLrMRo7LWuePwbeR1mB0xzqc64wQRhrTE38JF3arh2tkLVPBnRLWZAfRENEqcaB/A RzxhvDJoMWtHqseQutXC4KpvuJH4vgqUAbQTtUqSWSNPPPinVCBrmQoMX5yQpVxAWYPp X0eDYu4QPIhQ2rd44MynL8fe4p2LSThB56JEDExTLayA5pucKyyIeYw5BZbZxra8nJHv 9DbG2wIVMUYS3bvMWrqqptjGJ7yAxmGu8ZjqOafsjOekGTGZoBVxTrdXws9pYMO8JK2a oTwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=qKN1PglFlgOofJiNr4Baz1hTaTbHaIGFueL4oCIzYa8=; b=JyUAn6PmMmzYmfj5IuChrQlELUOwido6WfIYJ7u77LzrdV7KhBNZMtkeF5IDnp6Hai 1Fw/YbVOHEzpBzDV+YfBqII3ZGDEhTxQVdBhktjTBKvCp4sDDzv/2WKYbvp9FIusBT40 nBRaElWGuqIIGegtkGK19xcAcZwtUb+zRcLhosHURjTz+Addn5DMEnA+E6xPeO52McKb T1FYjD73AmxpdTiluA5HbbbJdAwBkREVnmxT/Sn+9ekTBQJoctbrrxpoaVkGY3EWnVzg 5CTAFhem/MlRdAXlq0SX5q4dHF6DmUqgJ3qmUWhmA1e7EurB83cFICug7r0VmtJIs0vp KWDA== X-Gm-Message-State: APf1xPByxeIzUDcAHknSlg76OqTneU+jHE84u+vfz80CPB2J3HVJsXF/ YKxPRvIWxlUHBbQKrf3NbkB5B7RZ X-Google-Smtp-Source: AG47ELtlC0l/bG+nfzkH+GEVtwvnajv//T6ivoSql5AwgaMcqDANyNPlIYFHw137m4931nzRTeDTCA== X-Received: by 10.223.209.65 with SMTP id b1mr3002893wri.277.1519945462260; Thu, 01 Mar 2018 15:04:22 -0800 (PST) Received: from [192.168.1.253] (host86-153-18-137.range86-153.btcentralplus.com. [86.153.18.137]) by smtp.googlemail.com with ESMTPSA id v63sm14274787wrc.69.2018.03.01.15.04.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 15:04:21 -0800 (PST) To: internals@lists.php.net References: Message-ID: <71120afe-503a-c83b-debd-a7913192d80f@gmail.com> Date: Thu, 1 Mar 2018 23:04:18 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Traits with interfaces From: rowan.collins@gmail.com (Rowan Collins) Hi all, On 01/03/2018 00:34, Marco Pivetta wrote: > - trait defined API can be imported with changed/aliased names, breaking > therefore the contact defined in the interface This isn't actually true, because trait method aliases create an *extra* copy of the pasted method, rather than actually renaming it. See example at the end of this e-mail for a demonstration. I'm not sure why this is; the original traits RFC [https://wiki.php.net/rfc/horizontalreuse#renaming] says that it is because of "the dynamic nature of PHP", but the example it gives doesn't actually show anything breaking. What *can* break an interface's contract is changing the *visibility* of the pasted method using "as protected" or "as private". This would need to be captured somehow while composing the class, probably producing a compile-time error, just as an explicit "implements" declaration would. While looking for the above RFC, I came across this draft by Kevin Gessner from 2 years ago for exactly the feature discussed here: https://wiki.php.net/rfc/traits-with-interfaces It includes references to potential uses of this feature, and equivalents in other languages. This appears to be the discussion in the archives, to avoid us repeating ourselves: https://marc.info/?t=145571923500003&r=1&w=2 and https://marc.info/?t=145573610000001&r=1&w=2 Appendix: Example of a trait providing implementation for an interface, even though the method was aliased: # https://3v4l.org/DMAoY interface Bobbable {     public function bob(); } trait Bobber {     public function bob() {         echo "Bobbity";     } } class Bibble implements Bobbable {     use Bobber { bob as bib; } } $b = new Bibble; $b->bob(); $b->bib(); Regards, -- Rowan Collins [IMSoP]