Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116805 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23938 invoked from network); 5 Jan 2022 00:10:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jan 2022 00:10:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 66AB51804C9 for ; Tue, 4 Jan 2022 17:17:24 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 ; Tue, 4 Jan 2022 17:17:23 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 669395C0105 for ; Tue, 4 Jan 2022 20:17:22 -0500 (EST) Received: from imap43 ([10.202.2.93]) by compute6.internal (MEProxy); Tue, 04 Jan 2022 20:17:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=tYngPB+5bqGVt++TBEf7N+bjSRxN9B/Z0vkuf1pOq yQ=; b=i3P7OIAKPOemia2+DAWEjIVyhIx2wh0zMy90HfKSPyrlobElTBn6Pjqxv vfnXxT1rDTXBQ55T0BcxObDswXFteKsPCh8uHZIpQp7bN/aTAs+uiabs3DjOjMSo XBhCxiRnuKHqcLZAcD0gX3n7a68zLPwX7LCruIbT1XDRz6GGp5pUlsawYC6XPzsF nLmrrUbsDIRg9MpRcC6qpNk3wv0Sb5ca7x0BFzpdU/935iC+XK4YpaAQDC+WCDMH EAy1XtGATSMB0Ub3jfu8tcIKrLKUi8g2r861DsAlm3E+GGVFVIgkEclIXn04esrB rmaZzkvYh0Dwa4C/Iv75MOTgSPdGg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrudefgedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2196FAC0E99; Tue, 4 Jan 2022 20:17:22 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4525-g8883000b21-fm-20211221.001-g8883000b Mime-Version: 1.0 Message-ID: In-Reply-To: <1641335738.195767637@f174.i.mail.ru> References: <1641335738.195767637@f174.i.mail.ru> Date: Tue, 04 Jan 2022 19:17:01 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC: Trait expects interface From: larry@garfieldtech.com ("Larry Garfield") On Tue, Jan 4, 2022, at 4:35 PM, Kirill Nesmeyanov wrote: > Hello internals! > > Since =C2=ABtraits=C2=BB are often an indicator of not very good code = and many=20 > may not use them quite correctly, for example, as helpers, I suggest=20 > adding support for the `expects`=C2=A0keyword to indicate that the tra= it is=20 > part of the code decomposition taking into account ISP. > > For example: > ``` > // Definition > > trait LoggerTrait expects LoggerInterface > { > =C2=A0 =C2=A0 // ... > } > > // Usage > > class MyService > { > =C2=A0 =C2=A0 use LoggerTrait; // Fatal Error: Class=C2=A0MyService=20 > expects=C2=A0LoggerInterface to be implemented > } > > class MyService2 implements=C2=A0LoggerInterface > { > =C2=A0 =C2=A0=C2=A0use LoggerTrait; // OK > } > ``` > > How relevant do you think this idea/proposal is? And what possible=20 > problems or solutions will this entail in the future? I can't say this has ever been an issue for me when using traits. I've = never had a trait that needed to be used by a class with a given interfa= ce. What I usually have is a trait that is a full or mostly implementat= ion of an interface. So this would be much more useful to me: trait LoggerTrait implements LoggerInterface { ... } (Perhaps some way to indicate that it mostly implements, and the rest ar= e abstract methods? Or require the other methods to be explicitly abstr= act?) I think it's subtly different, as it approaches the question from the ot= her direction. --Larry Garfield