PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_Template_Sigma » Bug #5168

Functions inside includes sometimes get »forgotten«

Details

Submitted2005-08-21 18:55 UTC
Fromchristian dot seiler at selfhtml dot org
Assignedavb
StatusClosed
PackageHTML_Template_Sigma
PHP Version4.3.11
OSLinux
Roadmaps(Not assigned)

Comments

[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', 'test@example.org');
$template->show();
?>

----------------- templates/test.html
<!-- INCLUDE test1.html -->

----------------- templates/test1.html
{home_mail:h}

Expected result:
----------------
test@example.org

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-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.