Bug #78795 [NEW]: Preg_replace does not always replace
| From: | markem at sim1 dot us | Date: | Fri, 08 Nov 2019 03:01:12 +0000 |
| Subject: | Bug #78795 [NEW]: Preg_replace does not always replace | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-223643@lists.php.net to get a copy of this message | ||
From: markem at sim1 dot us
Operating system: Windows 10
PHP version: 7.3.11
Package: Regexps related
Bug Type: Bug
Bug description:Preg_replace does not always replace
Description:
------------
---
From manual page: https://php.net/function.preg-replace
---
I was working on correcting a function by dawidgarus at gmail dot com.
Got it working (yeah!). But then decided to write my own and expand upon
it. That was when I ran into this problem:
If you use preg_replace, the "replace" string can not use the $x or ${x}
within another variable (like an array). This generates an error.
Test script:
---------------
function bc()
{
$argv = func_get_args();
$cmd = $argv[0];
$cmd = preg_replace( "/\$(\d+)/", $argv[$1], $cmd );
return( $cmd );
}
$a = bc( "sqrt($1*$1+$2*$2)", 3, 5 );
Expected result:
----------------
$a should equal "sqrt(3*3+5*5)"
Actual result:
--------------
Notice: Undefined variable: i in C:\Users\Mark\My
Programs\PHP\lib\bcd.php on line ###
--
Edit bug report at https://bugs.php.net/bug.php?id=78795&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78795&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78795&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78795&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78795&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78795&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78795&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78795&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78795&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78795&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78795&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78795&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78795&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78795&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78795&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78795&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78795&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78795&r=mysqlcfg