Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112326 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19025 invoked from network); 1 Dec 2020 07:59:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Dec 2020 07:59:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 34F231804C3 for ; Mon, 30 Nov 2020 23:27:01 -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=-1.5 required=5.0 tests=BAYES_00,HTML_MESSAGE, KHOP_HELO_FCRDNS,SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (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 23:27:00 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 5B9B65101324 for ; Tue, 1 Dec 2020 07:26:58 +0000 (UTC) To: internals@lists.php.net References: <265e9893-f82c-39f2-3323-2854b246658d@processus.org> Message-ID: Date: Tue, 1 Dec 2020 08:26:57 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------E3E1BD1668BCA5BF17D5470B" Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] Traits "implements" support From: pierre-php@processus.org ("Pierre R.") --------------E3E1BD1668BCA5BF17D5470B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Le 30/11/2020 à 16:19, Nikita Popov a écrit : > 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 Sorry for the misconception/confusion. Probably what's missing is something that looks like Java's interface with default methods, or something like that. Very often you use traits to partially implement an interface, and leave room for classes using this "partial implementation" for inheriting from another class. It looks like multiple inheritance without being it. What is really needed when doing this is: * Your class using this trait must implement the interface, * The trait methods must be validated against the interface contract. If I understand it well, when compiling PHP kinda copy-pastes the trait methods onto the class (trait doesn't exist as a type by itself, am I wrong?) then it validates the class, which solves the second point, trait methods are in the end, validated against the interface contract. What's missing here is the automatic interface usage, but more importantly, IDE support for the trait, and the information in the code that the trait does implement partially the interface (people who read the code cannot guess if it's mis-documented). Regards, Pierre --------------E3E1BD1668BCA5BF17D5470B--