Tuesday, May 06, 2008

php token_get_all LifeType

We are currently running lifetype, a opensource blog platform on a Gentoo Linux machine with Apache and PHP Version 5.1.2-pl1-gentoo. In this version of PHP the function token_get_all is not included. Lifetype, or to be more precise Smarty which is included in liftype to handle the templates uses this to extract non-cacheable parts out of compiled templates.

If you do not have the token_get_all function available some pages in lifetype will show the following error:

[error] [client xxxxxxxxx] PHP Fatal error: Call to undefined function token_get_all() in /usr/home/www/xxxxxxxxxx /public_html/class/template/smarty/internals/core.write_compiled_include.php on line 45

One solution is to add the function token_get_all so LifeType will work as intended, this however will require a recompile of php. A more simple hack is to change core.write_compiled_include.php which can generally be found in $lifetype/class/template/smarty/internals/.

On line 39 you will find a statement that makes sure that the function will only work when your php version is higher than version 5.0.

$this_varname = ((double)phpversion() >= 5.0) ? '_smarty' : 'this';

Now we do not want to have this executed so we change the required version from 5.0 to 7.0 which is not the version we are currently running. By making the change we make sure that there is never a call to token_get_all and by this we solve the problem.

$this_varname = ((double)phpversion() >= 7.0) ? '_smarty' : 'this';

This however is a quick and dirty hack, a better way is to recompile PHP with the token_get_all function included.

Post a Comment