Slashdot Mirror


Aspect-Oriented PHP

Bryan Saunders writes "

I am Bryan Saunders, and together with John Stamey and Matthew Cameron, we have developed an Extension to PHP to enable you to do Aspect-Oriented Programming with PHP. AOPHP 1.0 currently supports basic Before, After, and Around advice. Future versions will have more advanced support for these three types of advice. The Extension was developed using Java 1.5 and runs on Apache Web Servers. There are two parts to the implementation of AOPHP. The first involves using the Apache module ModRewrite, "the Swiss Army Knife of URL manipulation." The second is the aophpexec.aophp script which calls the AOPHP parser, written in Java 1.5. Aspects are written with a .aophp extension. These aspects are woven into incoming .php files by the Java AOPHP parser, contained in aophp.jar. For more information on AOPHP, visit http://www.aophp.net/ and For information on Aspect-Oriented Programming, visit http://www.aosd.net/ and http://www.aspectorientedprogramming.org/."

1 of 51 comments (clear)

  1. Re:Honest question: by Jerf · · Score: 2, Insightful

    Out of order quoting:

    I'm not sure what "thinking in Python" has to do with it though, you can't do a lot of it in Python either!

    You can't even dynamically add methods to PHP classes or dynamically modify the methods on an existing class.

    Python does that trivially.

    There are no hooks called before and after method calls, etc.

    There may not be hooks, but it's trivial to do in Python thanks to the previous point. In 2.4, the decorators can do this on a per-method basis, and to translate an entire class is pretty easy with a metaclass. Personally, I have yet to find a situation where this was useful and I didn't end up factoring it out, but I'm sure they exist. (I also have this problem with metaclasses; I keep solving problems with metaclasses, but I invariably factor them out; the only use I've kept for them so far is in cateloging various features of various classes. But that doesn't mean I think they are useless :-) )

    No way to access the syntax tree of a class.

    The full syntax tree, well, technically it is accessible but not in any useful way, so I'd say that Python can't do this. Generally, this is considered a bad thing in the community anyhow. I'm currently ambivalent; there are times I want it, but I do have to acknowlegde that also each of the times I've wanted it it would have made my code absolutely impenetrable to most programmers.

    Easy in Ruby due to the massive amount of runtime hooks and open classes.

    My impression is that other than the block syntax, Ruby and Python are as close to identical as you could hope for, and what one language does, the other has features to make up for. And the syntactic differences are a wash because almost every argument one person proffers in favor of one is considered a counter-argument by the other side. My favorite example: Ruby fan: "Ruby is more concise!" Python fan: "Why yes, yes it is, but that makes it less readable." Who is right? Both of them, really, for different people.