2013-05-16

I like the way Zend Framework works it's views and I make extensive use of partials but every partial include results in it's own file system hit. As I'm building my own framework I thought I could do better so this is what I came up with. What I'm looking for is any potential problems that I should watch out for and just general feedback.

First off lets take a simple template partial - we will call this template.phtml :

Next the actual class (proof of concept at this point so don't be hatin' on me too much)

and to use it the code would look like

So far on simple tests I'm showing about 8x speed increase with almost half the peak memory usage. I'm wondering where the down side is.

UPDATE

This was too interesting to not do so here is the revised code also on github

Again any feedback you can supply would be helpful.

UPDATE

Thinking about retooling some of the internals and changing the create_function call to use runkit_method_add. Big advantage that this would give is that template functions could be given a name (I was thinking a bastardization of the path to the template file) that would make any runtime template errors more meaningful. Currently create_function just reports "Error in runtime created function". Disadvantage is it is a PECL extension that doesn't have any windows binaries.

Anyone have any thoughts on that? Monkey patching the Templar object vs just creating anonymous functions is going to determine how view helpers will be implemented.

Show more