Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:116815
Return-Path: <azjezz@protonmail.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 60253 invoked from network); 5 Jan 2022 11:29:02 -0000
Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5)
  by pb1.pair.com with SMTP; 5 Jan 2022 11:29:02 -0000
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 836221804A7
	for <internals@lists.php.net>; Wed,  5 Jan 2022 04:36:27 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H3,
	RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no
	autolearn_force=no version=3.4.2
X-Spam-ASN: AS62371 185.70.40.0/24
X-Spam-Virus: No
X-Envelope-From: <azjezz@protonmail.com>
Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131])
	(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 <internals@lists.php.net>; Wed,  5 Jan 2022 04:36:26 -0800 (PST)
Date: Wed, 05 Jan 2022 12:36:22 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;
	s=protonmail2; t=1641386183;
	bh=CDzh/myKAZLnUv9PI/5t7aHHUeQBMPn70L55tAB2uR8=;
	h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To:
	 References:From:To:Cc;
	b=VQ669jK3Sq6fwP4fCG8Q431t7aY8XFX3AetMJBhz6kYvc8miJpyzgagLA8qMhoL23
	 7upuBC0oqHETAYXIWseyDeB5Iv5GlQSTR68YU9wTf1iZ1f9vcY8M43Av7ZQK8no9BN
	 OQDXcSzrqyF/qt0fwSTmPpHC9fQ+zaT94+teKFHKCgvi1MxhFoM0FlV46uoVzPg22u
	 3mXJpvpbFUCw0qOsPbImJAYaXOXtYPDm4EftPqq5FhRyhzLBIq6d20lyVBUT7Dpy/z
	 IEVyL3i+TBs8SU5MdSDurVP2GZFAmnl5VJmgRxIJu1Cq1BdD95fHDs75w8LtDI0lrM
	 7lKJNWU04cxOA==
To: Kirill Nesmeyanov <nesk@xakep.ru>
Cc: internals <internals@lists.php.net>
Reply-To: Saif Eddin Gmati <azjezz@protonmail.com>
Message-ID: <oV0RbVsgAgnJOykSmROAGncuwIDlj58JVeibgrmFcswfxlM9k9YELsrbBHdkmGfnESo4ZK-3c5NxGZ18S8DqV9BgCEHKa2FceMScuM9AZ94=@protonmail.com>
In-Reply-To: <1641335738.195767637@f174.i.mail.ru>
References: <1641335738.195767637@f174.i.mail.ru>
MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha256; boundary="------c92a10ae4ba524ee96fa9894e242d21e0ea4beffcb7205bee032939e08a5376a"; charset=utf-8
Subject: Re: [PHP-DEV] RFC: Trait expects interface
From: azjezz@protonmail.com (Saif Eddin Gmati)

--------c92a10ae4ba524ee96fa9894e242d21e0ea4beffcb7205bee032939e08a5376a
Content-Type: multipart/mixed;boundary=---------------------59373366eab544fe7e2a09adcec1f6a0

-----------------------59373366eab544fe7e2a09adcec1f6a0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;charset=utf-8

> Hello internals!
> =


> Since =C2=ABtraits=C2=BB are often an indicator of not very good code an=
d many may not use them quite correctly, for example, as helpers, I sugges=
t adding support for the `expects` keyword to indicate that the trait is p=
art of the code decomposition taking into account ISP.
> =


> For example:
> =


>     // Definition
>     =


>     trait LoggerTrait expects LoggerInterface
>     {
>         // ...
>     }
>     =


>     // Usage
>     =


>     class MyService
>     {
>         use LoggerTrait; // Fatal Error: Class MyService expects LoggerI=
nterface to be implemented
>     }
>     =


>     class MyService2 implements LoggerInterface
>     {
>         use LoggerTrait; // OK
>     }
>     =


> =


> How relevant do you think this idea/proposal is? And what possible probl=
ems or solutions will this entail in the future?
> =


> ------------------------------------------------------------------------=
---------------------------------------------------
> =


> Kirill Nesmeyanov


Hello Kirill

I really like to have this feature, this is not just useful for implementi=
ng interfaces, but also to enforce where a trait can be used.

e.g: if `ReadUserInputTrait` should only be used in console commands, so p=
utting a requirement to implement the console command interface, will ensu=
re that the trait is not misused.

However, i personally prefer the HackLang syntax of doing this.

Which is:

```
trait Foo
{
  require implements Bar;
  require extends Baz;
}
```

This syntax also will result in no new keywords, which is always preferred=
, but not necessarily a requirement.

ref: https://docs.hhvm.com/hack/traits-and-interfaces/trait-and-interface-=
requirements

Regards,

Saif Eddin Gmati.

https://void.tn
-----------------------59373366eab544fe7e2a09adcec1f6a0--

--------c92a10ae4ba524ee96fa9894e242d21e0ea4beffcb7205bee032939e08a5376a
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: ProtonMail

wsFzBAEBCAAGBQJh1ZCtACEJELAOCkaz8cFXFiEEOazMpP0wDQTIQG6zsA4K
RrPxwVdsfA/8CBpJ0lCxUfxNmi03OzKqZy1XdwTTvp3lsJGwP86U1nJUpmtl
hmm+UCfkQNDNUOwKaRfjq6HJUXyRfGZcMTgPWqbkd0arFZ3NWuUAAlF+rpIY
AUVpw8Ip2EBpiAa01WgvdTWHjJ8M43AnY1vT3MhQRJyJMi9/R7xHPAuFr2nO
mWbA027LJoDd0agySGIcozRdW8v6/h51HGRJpJpL3phi8SaY7CFOn7o4zh29
87rWa5TF2qrZzfLG9Bbyxn0WCsdmk27LzAEJBwV8wZrNyMi9d7Z4VlILeQtf
lSpD3U0LUJz2f5tb9dPfry1eRu77jouav/kmra/LMqK/ixAEdsMo6W7N6MxK
9uD6MgLUYeFGDSPwbOGDVojeGeHWiMZlQI9JiF5szEWfkf9G9FH785TgjBmJ
M4nuVRnuS84krNjGL2UsJlgYPqRo3SaVHoHEolH32xeqZfXFhyKxamUEr26S
vfE+ygTHP6HHh6dT6XFjOPzLJNik+69nS7LR4Y8sksJBjDIuBlgd3afO8miu
ZmOOaUQP3vl7Incv3qCgMKOkfqqLlR15/+vndZqRp+j95fpz1JdlshXH4oNi
stCyGQFoS4KH77nNL+rHwdRM1FydjTwnidSVgiJftVO9OlTWaSICuM9Q02WA
LjA71ffLdDzaJ74Wzkxa5r7tzSNJJGvWwHo=
=wI4f
-----END PGP SIGNATURE-----


--------c92a10ae4ba524ee96fa9894e242d21e0ea4beffcb7205bee032939e08a5376a--