Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92847 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42306 invoked from network); 27 Apr 2016 19:02:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Apr 2016 19:02:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.28.124 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.28.124 mx203.easyname.com Received: from [212.232.28.124] ([212.232.28.124:56433] helo=mx203.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/5A-20013-FDC01275 for ; Wed, 27 Apr 2016 15:02:58 -0400 Received: from cable-81-173-133-226.netcologne.de ([81.173.133.226] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1avUjc-00012M-2l; Wed, 27 Apr 2016 19:02:52 +0000 Reply-To: internals@lists.php.net References: <571BA0F0.2030400@fleshgrinder.com> <571C82A7.2060706@fleshgrinder.com> <571DCFA5.1090201@zend.com> To: Dmitry Stogov , internals@lists.php.net, Sara Golemon Message-ID: <57210CCF.3050506@fleshgrinder.com> Date: Wed, 27 Apr 2016 21:02:39 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <571DCFA5.1090201@zend.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="o4vVI53da61qPpbDushw8onAIL8RdnBLi" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] [RFC] PHP Attributes From: php@fleshgrinder.com (Fleshgrinder) --o4vVI53da61qPpbDushw8onAIL8RdnBLi Content-Type: multipart/mixed; boundary="W40DRfHvOFgAMtS28VB9Rl2moHcUQ9lD6" From: Fleshgrinder Reply-To: internals@lists.php.net To: Dmitry Stogov , internals@lists.php.net, Sara Golemon Message-ID: <57210CCF.3050506@fleshgrinder.com> Subject: Re: [PHP-DEV] [RFC] PHP Attributes References: <571BA0F0.2030400@fleshgrinder.com> <571C82A7.2060706@fleshgrinder.com> <571DCFA5.1090201@zend.com> In-Reply-To: <571DCFA5.1090201@zend.com> --W40DRfHvOFgAMtS28VB9Rl2moHcUQ9lD6 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 4/25/2016 10:04 AM, Dmitry Stogov wrote: >=20 >=20 > On 04/24/2016 11:24 AM, Fleshgrinder wrote: >> The invariant could also be added as an additional branch to the class= >> instead of a method, since it would not work like a method. >> >> class A {} invariant {} >> >> function f() {} require {} ensure {} >> >> This would also align nicely with closures and anonymous classes, whic= h >> is kind a problematic with annotations. >> >> $A =3D new class {} invariant {}; >> >> $f =3D function () {} require {} ensure {}; >> >> The only thing that remains that might be of interest to both is >> `@throws` but that was not discussed at all as of yet. >> >> use Ns\SomeException; >> >> @throws SomeException >> function f() { >> >> } >> >> This is at least how one would expect it to work and it is something >> that should be covered by annotations and not as part of the language.= >> The ABNF should account for that: >> >> ANNOTATION =3D "@" NAME [ " " VALUE ] >> NAME =3D STRING >> VALUE =3D QUOTED-STRING / PHP-REFERENCE / EXPRESSION >> QUOTED-STRING =3D ( "'" / DQUOTE ) STRING ( "'" / DQUOTE ) >> EXPRESSION =3D PHP-CODE ";" >> >> Where PHP references are any of the already possible ones: >> >> use F\Q\C\N; >> >> @annotation \F\Q\C\N >> @annotation N >> @annotation \F\Q\C\N::CONSTANT >> @annotation N::CONSTANT >> @annotation \F\Q\C\N::function() >> @annotation N::function() >> @annotation \F\Q\C\N::$variable >> @annotation N::$variable >> >> I also though some more about function support for annotations and thi= s >> would actually be a nice thing for userland. >> >> annotation deprecated(Reflection $element, string $message =3D '') = { >> @trigger_error($message, E_USER_DEPRECATED); >> } >> >> @deprecated('because') >> function x() {} >> >> @deprecated >> function y() {} >> >> This would allow users to implement simple and easy reactive annotatio= ns >> in userland. Even if this could or should be an extension of the featu= re >> in the future, it should be thought about know. Simply because the >> brackets make sense if such a feature is to be implemented. ;) >> > Looks interesting, but try to think where the "annotation deprecated" > should be declared,to be visible in every compiled script, when the > corresponding code should be called (in what context), what if we need > to do something at compile-time? Single answers to these question are > going to be great for "deprecated" use case, however they will limit > usability for other cases. >=20 > Thanks. Dmitry. >=20 Reactive annotations would have their limitations, e.g. calls to the reactive annotation function only happen during runtime and any attempts to perform something at compile time directly results in an engine error. It limits their use cases but allows interesting ones at the same time. Another approach could be to allow registration of reactive annotation functions at runtime, this would make it even more useful. Of course that would mean that the function is only called for each encountered annotation at runtime after it was registered. However, such a limitation is pretty much the same as we have it for any other function right now too. class User { public function hasRole($right) { if (false) { throw new InsufficientPrivileges; } } } $user =3D new User(); register_annotation('Framework\Role', [ $user, 'hasRole' ]); class Controller { @Framework\Role('admin') public function editAction(){} } // ENGINE (pseudo code) array registered_annotations =3D []; void register_reactive_annotation(annotation, callback) { registered_annotations[annotation] =3D callback; } void reactive_annotation_call(annotation, ...arguments) { if (annotation exists in registered_annotations) { call registered_annotations[annotation](...arguments); } else { log_info("Unknown reactive annotation %s", annotation); } } However, this is a story for another RFC. It is only important because usage of the brackets in the current RFC would make such a feature more complicated to implement. --=20 Richard "Fleshgrinder" Fussenegger --W40DRfHvOFgAMtS28VB9Rl2moHcUQ9lD6-- --o4vVI53da61qPpbDushw8onAIL8RdnBLi Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXIQzTAAoJEOKkKcqFPVVrlj4P/RMcVPbo6+BC6Qq6LGLCOSAV mpTUPlVQ1JrPyqZKJBm+j9G6YfNhXpwr+x6xapkHvVV9+jCZOPEJtupVb+EHZ+e6 AR0ATUsY2blzZjBqe1fqfkCqFSEFTkzi/CU5IFU9EBm6qxRiFTatbBLZNav2BELv iNjVmW/VxCKcKFIvE3sUotiJeYyOf84V4fp3hziSay8zR4bl1fyah5H0Xhh4KPaz Xk9gUnQmhd1u+/s9rwRq24GUFLq84UmPRoLymhhCsXBNJLiIP1eQXmiqD0fj1oCN OEQbvjmUaGnRR1+yPmCA14BuYCARHUbdtVavYiad7wcKETm0XVmUkjB3ur7DTJtD hVNFk++LOwneMLgcl80wkmANhvBcHiTO0yagPdClzCWh8U5mWuE9uJpu5RG4M68O 7WQ0SxdLKZsa0aX1WEF6WkHgqGzNwg5UIEabiyrcwAqD4EywHE5sYtbjZRSG4jwZ EOFgF+Z5qvQdFt82OLlbYbd61WQaHBMcDiPd0Tyejk/rH4uC59jBjjTP0v3Bpzsu lNUNJ3LonjFrFR3/DncPOzYecw7SfkIR+uPs7m2alr1MrO/xPlzI+YrXdHTYSrhz SLAsD3Y0t7dCt2mmmBNgamSmJ5XTU1ul2Y7Wt5wZyD/A1W5HigIAokaDgcgCsf6r QWWzphUl9mtf6uWIFOjC =hF/m -----END PGP SIGNATURE----- --o4vVI53da61qPpbDushw8onAIL8RdnBLi--