create_function strange behaviour
| From: | Bram van Leur | Date: | Mon, 10 Jun 2002 22:01:55 +0000 |
| Subject: | create_function strange behaviour | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-134@lists.php.net to get a copy of this message | ||
This is probably not a real Smarty bug, but I can only reproduce it's strange behaviour with Smarty using the following piece of code:
<?php
require 'Smarty.class.php';
$smarty = new Smarty;
$smarty->force_compile = true;
$smarty->register_prefilter(create_function('$a', 'return $a;'));
$smarty->display('a.tpl');
$smarty->display('b.tpl');
print_r($smarty->_plugins['prefilter']);
?>
It gives (with any Smarty 2.* version) an error about calling an function without a name. The a and b template just contain one word (like foo and bar).
After an hour of hunting this bug I found out that the _plugins['prefilter'] contains the following:
[] => Array('lambda_1', null, null, false)
This is quite strange because of the differing key and function name (as first element in the Array). Looking at register_prefilter shows me they are both set using the $function parameter. How can they differ?
Next load_plugin messes it up by setting a true to the wrong (new) entry. A second run on the same smarty object makes it real fun because of a fake (and loaded) plug-in entry.
Anyway, the thing that causes the trouble is the strange return of create_function. Can anyone tell me why the $function variable in register_prefilter has a different value the 2 times its used in the same statement?
--
Bram v. Leur
The Netherlands
Proud to PHP!