Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116839 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11105 invoked from network); 6 Jan 2022 18:44:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2022 18:44:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 27EC218053D for ; Thu, 6 Jan 2022 11:51:51 -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.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS57367 213.189.55.0/24 X-Spam-Virus: No X-Envelope-From: Received: from cache4.mydevil.net (cache4.mydevil.net [213.189.55.195]) (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 ; Thu, 6 Jan 2022 11:51:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=korulczyk.pl; s=devil; h=Content-Transfer-Encoding:Content-Type:In-Reply-To :MIME-Version:Date:Message-ID:From:References:To:Subject:Sender:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xvt6+R59pNFaXEq2lNIRWgLkBsj9dqqz6bFYEhPvea8=; b=mzh3MSc49w5iqFn8tLHTqxcyrI VKwHA6AgyHIHe4N5WqxjCV6hzHdldrRfc35NkPA27DifY1FLiEegpm9P0f8E88FzH2dnN7S68xXf7 d9pWLxtIbaop2kc7jwx8xBn5aVmBRO/CO1xnUTmdE44qZUZv1D+tYAux25BMAVQ/s1tw=; To: internals@lists.php.net References: <1641335738.195767637@f174.i.mail.ru> <5a4aebf8-e592-4517-8930-d18b112ef1fd@www.fastmail.com> <5a99809d-afda-546c-5a11-a4f0f821aa37@korulczyk.pl> Message-ID: Date: Thu, 6 Jan 2022 20:51:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-System-Sender: robert@korulczyk.pl X-System-UID: 1534 Subject: Re: [PHP-DEV] RFC: Trait expects interface From: robert@korulczyk.pl (Robert Korulczyk) > Your other points make sense, but I don't think this one does - there are no implicit interfaces in PHP*, so all any tool cares about is: > > 1) Does the class declaration say that it implements an interface? > 2) Does it actually contain the methods needed to do so, through any combination of direct implementation, inheritance, and trait usage? > > Knowing that a particular trait *could be* used to implement a particular interface without further code doesn't really tell the tool anything - it still has to resolve the list of methods on the class itself, and test those against the "implements" clause. You're talking about classes that use traits, but I'm talking about traits themselves. If I open a class in editor, there is a straightforward way to check if specific method is implementation of an interface - check interfaces implemented by class and if one of them have this method, then this method is implementation of this interface, and editor can properly mark it and handle navigation between implementation in class and declaration in interface. So even if I have a big project, you need to only load a subset of classes used by this project in order to find methods that are implementations of interfaces in this particular class. If I open trait in my editor, it is a lot more complicated. Editor needs to scan the whole project, find all classes that use this trait, find all interfaces that are implemented by these classes, and then find matches. And you may still end up with confusing results, because if you have class `A` that implements `FooInterface` and uses `FooTrait`, and also class `B` that uses `FooTrait`, but NOT implements `FooInterface`, then if you ask if `FooTrait::someMethod()` is implementation of `FooInterface::someMethod()`, the answer is "yes and no". Also, I'm not sure how it works now, but about 2 years ago I got rid of most of traits in one project, because navigation between trait and interface worked so badly in PhpStorm, that it was easier to deal with code duplication than broken "implements" detection. At the same time navigation between classes and interfaces worked without any problem. -- Regards, Robert Korulczyk