Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116842 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24623 invoked from network); 6 Jan 2022 22:45:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2022 22:45:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 802CC1804B1 for ; Thu, 6 Jan 2022 15:53:09 -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 15:53:08 -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=eKjKkCbukiPZduqr3bkHHFoQHfE2E9lBrv8ivOE1Twg=; b=oiN8MZDcGTZaEBYprsJBI5nICI StePK9VWq+Ov6eLuPp/VDlcz8+ZwFNlLgc83iSoSRdA76OV7czd+BzGHVpbl4TBsB51HamS6pETaF xpiZ/yuoQFIQG0uyXCUfqgMO7Q/xF7XQAkCKB9y9zljCgHIr1Af1ExU3lHsKiliVxQEM=; 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> <6E50C348-9452-40E1-ACE8-06DED11C9136@gmail.com> Message-ID: <9070564d-e138-81f6-c757-812d8962416e@korulczyk.pl> Date: Fri, 7 Jan 2022 00:53:05 +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: <6E50C348-9452-40E1-ACE8-06DED11C9136@gmail.com> 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) > In your use cases, are these traits generally *using* the interface methods, or *implementing* them? It is both. However "implementing" case is more problematic, since "using" can be quite reliably handled by adding `assert($this instanceof LoggerInterface)` or type hints in trait methods - SCA tools should handle this and PHP will complain if interface is not implemented. But there is no easy way to say "`FooTrait::someMethod()` is implementation of `FooInterface::someMethod()`" that PHP and SCA will understand. And I think this proposal handles this quite well, since it does not introduce implicit "implements" (IMO introducing another way of "injecting" interfaces to classes will just hurt readability) - you still needs to add interface to "implements" section in class definition, but traits have more tools to define its purpose and ensure that classes have proper definition. -- Regards, Robert Korulczyk