From: zionwilson at gmail dot com
Operating system: Windows Vista x64 Ultimate
PHP version: 5.2.6
PHP Bug Type: Regexps related
Bug description: parse problem on preg_replace
Description:
------------
for the function preg_replace() i guess it does comparison and other
operation before parse the result from '\\3', '\\2', '\\1' when use a
'general' match pattern like ([1-9][0-9]*)
hence inval() won't work because for string '\\3' or '${3}' the result is
always zero.
however 'modifier-like' match pattern like \d, works well.
so what is the fast work around if i need php to parse "\\1" before doing
any operation like inval(), or comparison, at the moment?
Reproduce code:
---------------
<?
$c1 = "2 4 8";
$cp1 = "/(\d)\s(\d)\s(\d)/e";
$cr1 = "'\\3*\\2+\\1='.(('\\3')*('\\2')+('\\1'))";
$c2 = "2 4 8";
$cp2 = "/([1-9][0-9]*)\s([1-9][0-9]*)\s([1-9][0-9]*)/";
$cr2 = "'\\3*\\2+\\1='.(('\\3')*('\\2')+('\\1'))";
$c3 = "2 4 8";
$cp3 = "/([1-9][0-9]*)\s([1-9][0-9]*)\s([1-9][0-9]*)/";
$cr3 = "'\\3*\\2+\\1='.(('\\3')*('\\2')+('\\1'))";
$c4 = "2 4 8";
$cp4 = "/([1-9][0-9]*)\s([1-9][0-9]*)\s([1-9][0-9]*)/";
$cr4 = intval('\\3')*intval('\\2')+intval('\\1');
$c5 = "2 4 8";
$cp5 = "/([1-9][0-9]*)\s([1-9][0-9]*)\s([1-9][0-9]*)/";
$cr5 = ('\\3' == '${3}' ? '${3}' . ' equals to ' . '\\3' : '${3}' . 'not
equals to' . '\\3');
echo (preg_replace($cp1,$cr1,$c1));
echo ("<br>");
echo (preg_replace($cp2,$cr2,$c2));
echo ("<br>");
echo (preg_replace($cp3,$cr3,$c3));
echo ("<br>");
echo (preg_replace($cp4,$cr4,$c4));
echo ("<br>");
echo (preg_replace($cp5,$cr5,$c5));
?>
Expected result:
----------------
8*4+2=34
8*4+2=34
8*4+2=34
34
8equals to8
Actual result:
--------------
8*4+2=34
'8*4+2='.(('8')*('4')+('2'))
'8*4+2='.(('8')*('4')+('2'))
0
8not equals to8
--
Edit bug report at http://bugs.php.net/?id=45642&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=45642&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=45642&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=45642&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=45642&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=45642&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=45642&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=45642&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=45642&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=45642&r=support
Expected behavior: http://bugs.php.net/fix.php?id=45642&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=45642&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=45642&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=45642&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45642&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=45642&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=45642&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=45642&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=45642&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=45642&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=45642&r=mysqlcfg