From: [EMAIL PROTECTED]
Operating system: WinNT 2000
PHP version: 4.2.1
PHP Bug Type: Scripting Engine problem
Bug description: Exception of the parsing engine of variables in preg_replace()
When the reference identificator in replacement parameter is followed by
other regular php variable, the variable is parsed, and after that the
number of reference is catched.
<?
$str = "Something to be replaced 7";
$rpl = 6;
echo preg_replace("/^(.*?)[0-9]*$/", "\\1$rpl", $str);
?>
When I expect 7 to be replaced with 6, preg_replace() searches for
reference \\16. The problem can be resolved with adding some /e stuff, ot
just modifying the regexp.
<?
$str = "Something to be replaced 7";
$rpl = 6;
echo preg_replace("/^(.*?)[0-9]*$/e", "'\\1'.\$rpl", $str);
?>
Even, I can use some of the things proposed in:
http://bugs.php.net/bug.php?id=15166
Ok, but /e makes the whole thing slower...\\1\\99$rpl is a good solution,
but what happens when the maximum number of references becomes 999? :-)
So, the behavior of the function is a little strange in this
case...because in the second parameter two things has to be parsed. Once
php variables, and then regexp references.
In my opinion, this is a bug. Maybe it's difficult to change the whole
parsing mechanism of php cause of one exception, but the exception is
already there - references can be numbers (like in Perl), $1, $2, etc...
--
Edit bug report at http://bugs.php.net/?id=20150&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=20150&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=20150&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=20150&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=20150&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=20150&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=20150&r=support
Expected behavior: http://bugs.php.net/fix.php?id=20150&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=20150&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=20150&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=20150&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20150&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=20150&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=20150&r=isapi