From: michiel at tincan dot co dot uk
Operating system: Linux
PHP version: 4.3.2
PHP Bug Type: PCRE related
Bug description: pattern emtpy and replacement array
Description:
------------
When upgrading to 4.3.2 this started to happen:
whenever I use
$string = preg_replace("/\[$pattern\]/",$replacement,$string)
and the $pattern is empty or does not exist, but the replacement is an
array, my string is made empty.
'. /configure' '--prefix= /usr /local' '--with-apxs= /usr /local
/apache-1.3.27 /bin /apxs' '--with-config-file-path= /etc' '--with-mysql=
/usr' '--with-ldap' '--enable-sysvshm=yes' '--enable-sysvsem=yes'
'--with-gd= /usr' '--with-gettext' '--with-xml' '--with-imap'
'--enable-sockets' '--enable-ftp' '--with-regex=system'
'--enable-track-vars=yes' '--enable-force-cgi-redirect=yes'
'--enable-memory-limit=yes' '--enable-debug=no'
Register Globals is "on"
Reproduce code:
---------------
$data = array(
"field1" => "somevalue",
"field2" => array("hmm","whassup"),
);
$html = '<b>[field1]</b>
,<h1>[field3]</h1>';
while (list($field,$fielddata) = each ($data)) {
$html = preg_replace("/\[$field\]/",$fielddata,$html);
}
print $html;
# will print nothing. however if you comment out the line "field2" etc
above, it will print something
Expected result:
----------------
output should be :
<b>somevalue</b>
, <h1>[field3]</h1>
Actual result:
--------------
no output, the string $html is empty
--
Edit bug report at http://bugs.php.net/?id=25042&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25042&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25042&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=25042&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=25042&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=25042&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=25042&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=25042&r=support
Expected behavior: http://bugs.php.net/fix.php?id=25042&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=25042&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=25042&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=25042&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25042&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=25042&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=25042&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=25042&r=gnused