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

Lars Strogny:
The state of meta programming in PHP
Dec 03, 2012 @ 15:03:29

Lars Strojny has written up a new post about the current state of metaprogramming (software that writes other software) and how it sits in today's PHP functionality including some current features to make it happen.

Metaprogramming is quite an interesting sub-discipline and knowing about certain techniques and tools allows you to cut corners quite dramatically for certain tasks. As always, don't overdo but to find out when you are overdoing, first start doing, get excited, overdo, find out the right dose. Let's have a look at what kind of tools you have available in PHP to solve typical meta programming problems.

He starts by defining what kinds of things metaprogramming can and can't do (like type introspection, lower level syntax inspection and metadata management) and gets into what you can use in/with PHP for each. He mentions several tools, some internal to PHP - like the Reflection API and the Tokenizer extension - as well as external projects like the PHP-Parser, doctrine-common package.

tagged: metaprogramming language tools extension library

Link:


Trending Topics: