Bug #10666: preg_replace 'e' modifier
| From: | smoonen at andstuff dot org | Date: | Fri, 04 May 2001 15:27:54 +0000 |
| Subject: | Bug #10666: preg_replace 'e' modifier | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-53851@lists.php.net to get a copy of this message | ||
From: smoonen@andstuff.org
Operating system: Linux
PHP version: 4.0.5
PHP Bug Type: PCRE related
Bug description: preg_replace 'e' modifier
Formerly, preg_replace's "e" modifier inserted extraneous backslashes in
backreferences of "\\1" or '\\1' form.
Ostensibly, the $1 backreference form was added to fix this. However, the following code fails:
function f($x) { return 'yo'; }
$s = "xyzabc def123";
$s = preg_replace('/(abc def)/e', 'f($1)', $s, -1);
It seems to be trying to evaluate $1 as code, rather than as a variable containing the contents
"abc def".
This is borne out by the fact that the following succeeds:
$s = preg_replace('/(abc def)/e', 'f("$1")', $s, -1);
But "$1" and '$1' are no better than "\\1" and '\\1', since
it still inserts extraneous backslashes before single quotes or double quotes (respectively)!!!
I was sincerely hoping that PHP 4.04 and 4.05 would fix this oversight, since my web application
depends on it. I'm keeping my fingers crossed that it's just me doing something wrong,
though I doubt it...
--
Edit Bug report at: http://bugs.php.net/?id=10666&edit=1