#20392 [Com]: HTML_Template_IT error with $ in values
| From: | olonoh at yahoo dot com | Date: | Fri, 15 Nov 2002 02:57:43 +0000 |
| Subject: | #20392 [Com]: HTML_Template_IT error with $ in values | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-10820@lists.php.net to get a copy of this message | ||
ID: 20392
Comment by: olonoh@yahoo.com
Reported By: olonoh@yahoo.com
Status: Assigned
Bug Type: PEAR related
Operating System: Linux
PHP Version: 4.2.2
Assigned To: nicos
New Comment:
OK, thanks. I think the patch I provided should fix the bug. Looking
at the code, the preg_replace() method is used to match the delimeters
+ variable name even though that will never contain a regular
expression. There also isn't any of that match reused in the
substitution (i.e. the $1, $2, \1, \2, etc. variables). So
str_replace() should be an acceptable replacement while fixing the
bug.
By the way, I should probably continue in saying that the bug only
affects values with characters representing those match variables --
$1, $2, \1, \2, etc. -- not just any dollar sign character combo.
Previous Comments:
------------------------------------------------------------------------
[2002-11-14 20:43:52] nicos@php.net
I got the point. I don't think this can be fixed anyway. I will talk
about it with the maintainer.
Thanks you, I will let you know.
------------------------------------------------------------------------
[2002-11-14 20:36:29] olonoh@yahoo.com
I'm not clear how that's expected behavior. I'm not referring to PHP's
handling of strings, but of IT.php's usage of preg_replace() instead of
str_replace(). I understand that this is necessary:
$value = "\$1"
but if I can print $value to STDOUT with the dollar sign, I don't
understand why I have to escape it again before substituting it for a
template variable.
If the value isn't explicitly defined in my code, form input for
example, I'd have to substitute all '$' for '\$' and then revert back
to the original value if I wanted to use it in something other than
IT.php.
------------------------------------------------------------------------
[2002-11-14 20:25:32] nicos@php.net
Yes I understand it, but it's an excepted behaviour of the ZendEngine.
Just add put a backslash before '$'.
Thanks for your report.
------------------------------------------------------------------------
[2002-11-14 20:22:11] olonoh@yahoo.com
I think you misunderstood the report. The $1 was the literal value
(note the single quotes around the string). When IT.php processes the
value it's evaluated instead of being taken literally -- I wouldn't
think that'd be expected behavior. Try this modified example:
<?php
require_once('HTML/IT.php');
$value = 'I have $1 in my pocket';
$t = new IntegratedTemplate;
$t->setTemplate('{x}', TRUE, TRUE);
$t->setVariable('x', $value);
print $value."\n";
$t->show();
?>
This prints:
I have $1 in my pocket
I have in my pocket
The first time it's printed correctly, but after it's processed in
IT.php it's printed incorrectly.
------------------------------------------------------------------------
[2002-11-14 20:06:07] nicos@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/20392
--
Edit this bug report at http://bugs.php.net/?id=20392&edit=1