Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.0

Bug #5168 Functions inside includes sometimes get »forgotten«
Submitted: 2005-08-21 18:55 UTC
From: christian dot seiler at selfhtml dot org Assigned: avb
Status: Closed Package: HTML_Template_Sigma
PHP Version: 4.3.11 OS: Linux
Roadmaps: (Not assigned)    

 [2005-08-21 18:55 UTC] christian dot seiler at selfhtml dot org
Description: ------------ When using functions inside includes (e.g. test.html includes test1.html and test1.html contains {variable:h}) sometimes the expression {variable:h} does not get replaced. Please have a look at the example script for a demonstration. The reason: You do $funcId = substr(md5(serialize($funcData)), 0, 10); to generate an ID for this function. This works fine as long you do *not* have includes. When you have includes it still works fine *if* (and only if) the substring does not entirely consist of digits. If it *does* entirely consist of digits, PHP will treat the array index of $this->_functions[$block][$funcID] as a numer and the call to array_merge() in _pullTriggers will force the array to be renumerated. Possible bugfixes: 1) make sure non-numeric IDs are generated, e.g. replacing all occurrences of $funcId = substr(md5(serialize($funcData)), 0, 10); with $funcId = 'F'.substr(md5(serialize($funcData)), 0, 10); 2) don't do array_merge but use the + operator, so replace $this->_functions[$parents[0]] = array_merge($this->_functions[$parents[0]], $this->_functions[$placeholder]); with $this->_functions[$parents[0]] = $this->_functions[$placeholder] + $this->_functions[$parents[0]]; (in _pullTriggers) Test script: --------------- ----------------- test.php <?php require_once 'HTML/Template/Sigma.php'; $template =& new HTML_Template_Sigma('./templates'); $template->loadTemplateFile('test.html'); $template->setVariable('home_mail', ''); $template->show(); ?> ----------------- templates/test.html <!-- INCLUDE test1.html --> ----------------- templates/test1.html {home_mail:h} Expected result: ---------------- Actual result: -------------- [no output]


 [2005-08-21 19:11 UTC] christian dot seiler at selfhtml dot org
Additional note: In this example the substring of the MD5 hash is '7455632580'. Therefore the given example will *only* show the bug on 64bit systems - on 32bit systems the class will behave correctly because 7455632580 does not fit into 32 bits. Nevertheless, an MD5 hash may also start with a 0 digit and therefore this bug also affects 32bit systems - it's just that probably nobody has yet come up with a digit-only MD5 hash of this function data that starts with.
 [2005-08-30 11:02 UTC] avb
Looks like your analysis is right, though the bug is indeed quite hard to reproduce. Thanks for such a thorough report!
 [2005-09-29 13:44 UTC] christian dot seiler at selfhtml dot org
May I ask when this will be fixed in the official version? I don't really like to be forced to have a patched version of a PEAR package installed.
 [2005-11-05 13:33 UTC] avb
Fixed in release 1.1.4