Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62553 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19586 invoked from network); 27 Aug 2012 06:06:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Aug 2012 06:06:35 -0000 Authentication-Results: pb1.pair.com header.from=ralph@ralphschindler.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=ralph@ralphschindler.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain ralphschindler.com from 209.85.214.170 cause and error) X-PHP-List-Original-Sender: ralph@ralphschindler.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:52810] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3B/A7-13425-A6E0B305 for ; Mon, 27 Aug 2012 02:06:34 -0400 Received: by obbwc18 with SMTP id wc18so8516633obb.29 for ; Sun, 26 Aug 2012 23:06:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=29ZKINF7a/8pxHotZt0zhPXuHey861w7V93Ga1dVpOA=; b=aFBNMVNZfTqdZUpl75FZfV5K/U81jEkf+6IN5grplxoyM7EHMT3W3pJ0k1QLqRKcgF ueJBKeNZ689UCh2UnpmQZlPpCxJdYMTExJEJOfZEH3DrZuwzZRL5n8XMOE0Y7o8tTbvV wh3WnhRSVmj7WslcWi6TfIi6LKIEG+4kyLWagYQ4h8wNZmTcFH9kOU55bvNDetx25l1F nyyNZrPrt8Lv5kUEi1elvybLebpiGB2ry+d+PCluJVxsfw5X5uu98IIhuMSqa/MWn5r3 F6l4Zv3P9Chv0VRB6Q2xBun3qusnoc0QU5/4OGxrDEMEt/5quxhsMhjZpIauEsvYZnqj qunA== Received: by 10.60.0.194 with SMTP id 2mr9054116oeg.108.1346047591598; Sun, 26 Aug 2012 23:06:31 -0700 (PDT) Received: from Ralphs-Mac-Pro.local (ip174-73-14-247.no.no.cox.net. [174.73.14.247]) by mx.google.com with ESMTPS id kf5sm16395723obc.7.2012.08.26.23.06.30 (version=SSLv3 cipher=OTHER); Sun, 26 Aug 2012 23:06:31 -0700 (PDT) Message-ID: <503B0E65.6090904@ralphschindler.com> Date: Mon, 27 Aug 2012 01:06:29 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmX+9ulSD/N9mphSfledjbt3m3HbrDArs5TSi5ADjBdVjkj/JZ/+v6WyI8ppt6Vyfk6h803 Subject: Re: [PHP-DEV] Aspect Oriented Programming in PHP From: ralph@ralphschindler.com (Ralph Schindler) On 8/26/12 7:21 PM, Rasmus Schultz wrote: > But AOP is just one of many popular techniques that require code > generation. And for that matter, there is an endless number of different I'm failing to see what code generation you talking about. Could you elaborate about how AOP and code generation relate? > I would much prefer to see the language enhanced on a lower level - to > enable solid, reliable, efficient implementations of code generation in > userland, paving the way for good AOP frameworks, as well as many other > techniques and ideas, now and in the future. > > Thanks to bytecode caching, and various other advances in efficiency in the > past few years, PHP in general is (or could be) a brilliant language for > code-generation tasks. For instance, check out this elegant parser library: The benefit of AOP as a low-level (it is as low level as say, xdebug) extension is massive. AOP solves the problem of cross cutting concerns. In PHP, if you don't want to rely on globally accessible API's, solving this problem usually entails injecting another object. So now, your $controller object is injected with a $logger object, $authentication object, $session object, $caching object, etc. Currently, all of the major frameworks are attempting to provide AOP stylings though a Javascript-esque event/signal manager. To do this, code must be littered with something like the following: class Foo { public function doA() { $events->trigger('beforeA', $this); // actually do A $events->trigger('afterA', $this); } public function doB() { $events->trigger('beforeB', $this); // actually do A $events->trigger('afterB', $this); } // repeat for every other interesting method } Now, $events could be a dependency, it could be some object that shares a static scope, or it could actually be a static call like Events::trigger(). Whatever the case, any code that wants to subscribe to this AOP-esque style of allowing non-descript collaborators to "advise" or coalesce into the workflow has to follow this pattern .. all over the place. $this might be $this, but in many cases, it is a context object that bundles up necessary info including $this. With ext/AOP, all of that goes away. Objects can get back to just doing what their core objective was (even application services / models / controllers) and they don't have to care that a logger now wants to log something about what a controller is doing, or (taken a step further) that somewhere in the code an authentication aspect was registered to ensure a particular set of controllers is only accessed by users who are logged in. In short, the only aspect of this particular extension that does anything slightly related to parsing is it has a syntax for doing the "engine level" hooking. (Think of is as a DSL/syntax for setting smart breakpoints with a debugger). > Also, consider how much simpler it would be to implement things like > template engines... Not sure I follow here either. -ralph