Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Imagine Easy:
Pushing the limits of metaprogramming in PHP: aspect oriented design
Feb 20, 2014 @ 18:01:05

In a new post to the "imagine easy" blog Yitzchak Schaffer looks at Aspect Oriented Programming in PHP and pushing the limits of some of the work already done in the area.

Here’s the premise [of Aspect Oriented Programming]. A given piece of code exists for a certain purpose - let’s say, to retrieve a record from a database. But there may be any number of other things that need to happen in addition to the actual retrieval: logging, access control, caching… those are known as cross-cutting concerns - issues that are relevant across the codebase, but are not specifically relevant to any one piece of code where they might be needed. And being that these bits of functionality are not intrinsically connected with data retrieval, in our example, it would make sense for them to be disconnected from the retrieval implementation.

He includes some example code showing the migration from a typical logging example, moving the logging code away from the other parts and into an "aspect". He briefly mentions some caching functionality and talks about how one PHP framework, Lithium, makes use of these kinds of AOP principles. He offers an alternative in the form of subtypes, and example of which he's implemented in a tool of his own, Camphor.

tagged: aop aspectoriented design metaprogramming example introduction

Link: http://dev.imagineeasy.com/post/77176594791/pushing-the-limits-of-metaprogramming-in-php-aspect


Trending Topics: