RE: [PHPLIB] Difference between phplib templates and FastTemplate?? From: Alexander Aulbach (ssilk <email protected>)
Date: 03/20/00

On Mon, 20 Mar 2000, Stanislav Malyshev wrote:
}HH>> $var["VARNAME"] in one pass (I think it's one pass... I used a
}HH>> generic {[a-zA-z0-9]*} regexp and replaced it with $var["\\1"]),
}HH>> and then used eval() to have the variables replaced with the
}HH>> actual values. I was never sure if this was better than running
}
}I'm using this, and it seems to be faster (I actually did benchmarked it
}and it was faster, but you know, there always are some 1001 cases where
}benchmark lies). The idea is as follows:
}
}1. Change all {VAR} to $T_ARR[VAR] (name T_ARR is arbitrary) in template.
}2. Generate following text:
}
}function T_F_<random_id> ($T_ARR) {
}return <<<ENDT
}<template with T_ARR goes here>
}ENDT;
}}
}
}3. Eval this text.
}4. Now you have compiled template that substitutes variables with speed of
}Zend executor, not with speed of regexp (which ought to be faster, since
}extra regexp step on every substitution is eliminated). You just store
}that <random_id> and call T_F_<random_id> when you need to substitute
}template.
}
}The downside, obviously, is that once template is compiled it can't be
}changed (though it might be also security feature :), and that namespace
}is polluted with that functions (though it isn't really a problem - just
}choose distinctive prefix to function names). Also, it works only in PHP
}4.
}
}The up-side is that on frequently-used multi-variable templates it should
}give significant speedup - template is parsed only once (in fact, twice -
}once by regexp and once by Zend parser).
}
}The code doing this is really working, and requires very small changes. I
}tried to interest somebody from PHPLIB group in it, but got absolutely no
}any interest.

Hum, this will work only with PHP4...

-- 

SSilk - Alexander Aulbach - Herbipolis/Frankonia Minoris - (0931)22032

- PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>. To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in the body, not the subject, of your message.