Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78671 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3907 invoked from network); 4 Nov 2014 18:58:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2014 18:58:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.245 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.245 imap11-3.ox.privateemail.com Received: from [198.187.29.245] ([198.187.29.245:58690] helo=imap11-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/20-02095-EC129545 for ; Tue, 04 Nov 2014 13:58:22 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id D746A880106; Tue, 4 Nov 2014 13:58:18 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id khVpcq1dS4ku; Tue, 4 Nov 2014 13:58:18 -0500 (EST) Received: from oa-edu-170-172.wireless.abdn.ac.uk (oa-edu-170-172.wireless.abdn.ac.uk [137.50.170.172]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id E4CE7880107; Tue, 4 Nov 2014 13:58:16 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) In-Reply-To: <54591A76.8070302@sugarcrm.com> Date: Tue, 4 Nov 2014 18:58:15 +0000 Cc: Benjamin Eberlei , Pierre Joye , Levi Morrison , PHP internals , Larry Garfield Content-Transfer-Encoding: quoted-printable Message-ID: <967E30E5-71CB-40F8-9AE2-733D327DE197@ajf.me> References: <5457AF2F.90808@php.net> <5457BDB7.8070701@garfieldtech.com> <54589A8D.3020607@sugarcrm.com> <1C3F4FA3-ABD5-4F6F-A898-F63AC1C723D5@ajf.me> <54591A76.8070302@sugarcrm.com> To: Stas Malyshev 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 18:27, Stas Malyshev wrote: >=20 > For python-style decorators, at least the way they work in Python, = we'd > need to organize our function tables differently, as Python just > replaces the function with another one while decorating, and I'm not > sure it'd be as easy to do with PHP. Are you sure this would be difficult? We could create a closure of the = class method (trivial to do), pass it to a userland function upon = creating the class (the former is easy, the =E2=80=9Cupon creating the = class=E2=80=9D is the issue), and use the closure it returns as the = class method. There=E2=80=99d be issue with autoloading to iron out, but = I don=E2=80=99t think it=E2=80=99d be a problem. > You'd have to convert all such functions to closures (or something = that > can be both, maybe) and have the engine be aware that function table = now > can store closures. And, also, inheritance may get a bit weird there. = It > would be very powerful, but it may not be very simple to do. A closure is just a normal function, actually. The Closure class just = wraps a zend_function and a this pointer. There=E2=80=99s no reason you = couldn=E2=80=99t substitute here. I believe you could literally just = copy the zend_function across, though there=E2=80=99d obviously be some = complications. Not sure about inheritance. > Also, it is a major overkill for what annotations are commonly used - > attaching a piece of data to an entity. In Python, decorators are very > powerful for modifying function behavior (i.e., attaching pre/post > conditions to functions or doing some things phpunit does is really > easy) but it is too much for just attaching data. This is useful for merely attaching data as well (just return the = function passed), but it also enables manipulating the function. It = could replace some cases of merely attaching data, too, by making the = function do something itself, rather than having something else do = something if a function has a certain annotation, when calling that = function (if that makes any sense). -- Andrea Faulds http://ajf.me/