Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78663 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90340 invoked from network); 4 Nov 2014 18:27:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2014 18:27:07 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 108.166.43.67 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 108.166.43.67 smtp67.ord1c.emailsrvr.com Linux 2.6 Received: from [108.166.43.67] ([108.166.43.67:42463] helo=smtp67.ord1c.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/EE-06676-A7A19545 for ; Tue, 04 Nov 2014 13:27:06 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp25.relay.ord1c.emailsrvr.com (SMTP Server) with ESMTP id CD13E180405; Tue, 4 Nov 2014 13:27:03 -0500 (EST) X-Virus-Scanned: OK Received: by smtp25.relay.ord1c.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 095321803F4; Tue, 4 Nov 2014 13:27:02 -0500 (EST) X-Sender-Id: smalyshev@sugarcrm.com Received: from Stass-MacBook-Pro.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net [108.66.6.48]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA) by 0.0.0.0:465 (trex/5.3.2); Tue, 04 Nov 2014 18:27:03 GMT Message-ID: <54591A76.8070302@sugarcrm.com> Date: Tue, 04 Nov 2014 10:27:02 -0800 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Andrea Faulds , Benjamin Eberlei CC: Pierre Joye , Levi Morrison , PHP internals , Larry Garfield References: <5457AF2F.90808@php.net> <5457BDB7.8070701@garfieldtech.com> <54589A8D.3020607@sugarcrm.com> <1C3F4FA3-ABD5-4F6F-A898-F63AC1C723D5@ajf.me> In-Reply-To: <1C3F4FA3-ABD5-4F6F-A898-F63AC1C723D5@ajf.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Annotation PHP 7 From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > The approach for annotations that I like best would actually be not > annotations, but Python-style decorators. They’re very simple, but > very powerful. They would allow you to do annotations, but also add > extra functionality to functions. 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. > Which would be equivalent to the following PHP code: > > $myfunc = function myfunc() { # function source code here }; $myfunc > = some_decorator($myfunc, foo, bar); Not really, because functions work differently in Python and in PHP. You can not just replace a function in class's function table with random closure in PHP, at least easily. 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. 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. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/