Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78648 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62689 invoked from network); 4 Nov 2014 16:34:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2014 16:34:27 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.208 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.208 imap2-3.ox.privateemail.com Received: from [192.64.116.208] ([192.64.116.208:50639] helo=imap2-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5F/99-06676-21009545 for ; Tue, 04 Nov 2014 11:34:27 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 2519E8C007D; Tue, 4 Nov 2014 11:34:24 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap2.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap2.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id mqt2k3TbJ96J; Tue, 4 Nov 2014 11:34:23 -0500 (EST) Received: from oa-res-26-28.wireless.abdn.ac.uk (oa-res-26-28.wireless.abdn.ac.uk [137.50.26.28]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 776428C007B; Tue, 4 Nov 2014 11:34:22 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) In-Reply-To: Date: Tue, 4 Nov 2014 16:34:20 +0000 Cc: Pierre Joye , Stas Malyshev , Levi Morrison , PHP internals , Larry Garfield Content-Transfer-Encoding: quoted-printable Message-ID: <1C3F4FA3-ABD5-4F6F-A898-F63AC1C723D5@ajf.me> References: <5457AF2F.90808@php.net> <5457BDB7.8070701@garfieldtech.com> <54589A8D.3020607@sugarcrm.com> To: Benjamin Eberlei X-Mailer: Apple Mail (2.1990.1) Subject: Re: [PHP-DEV] Annotation PHP 7 From: ajf@ajf.me (Andrea Faulds) > On 4 Nov 2014, at 10:54, Benjamin Eberlei wrote: >=20 > I agree with Stas that a much simpler approach is probably realistic. >=20 > beginning pure speculation here, i see a short array like syntax like: >=20 > [foo=3D"bar", bar=3D"baz", baz=3D["key": "value"]] > function annotated_fn() {} >=20 > Maybe even exactly short array syntax: >=20 > ["foo"=3D"bar", "bar"=3D"baz", "baz"=3D["key": "value"]] > function annotated_fn() {} >=20 > Then $reflectionFunction->getAnnotations() returns an array. Various > PHP/Userland libraries and frameworks can then stick whatever symantic = on > top that they want. The approach for annotations that I like best would actually be not = annotations, but Python-style decorators. They=E2=80=99re very simple, = but very powerful. They would allow you to do annotations, but also add = extra functionality to functions. In Python, a decorator is a function (or callable object), and you use = one like this: @some_decorator(foo, bar) def myfunc(): # function source code here This is actually syntactic sugar for the following: def myfunc(): # function source code here myfunc =3D some_decorator(myfunc, foo, bar) Which would be equivalent to the following PHP code: $myfunc =3D function myfunc() { # function source code here }; $myfunc =3D some_decorator($myfunc, foo, bar); Basically, Python decorators allow you to explicitly have a function = modify a new function before it=E2=80=99s declared. This is pretty = useful: If your decorator does nothing, it=E2=80=99s just an annotation. = But you can also use it to add functionality. For example, you might = make a decorator that does something before and after a function runs. -- Andrea Faulds http://ajf.me/