ID: 25042
Updated by: [EMAIL PROTECTED]
Reported By: michiel at tincan dot co dot uk
Status: Bogus
Bug Type: PCRE related
Operating System: Linux
PHP Version: 4.3.2
New Comment:
With latest CVS snapshot, it errors out and doesn't do anything.
Previous Comments:
------------------------------------------------------------------------
[2003-08-12 09:12:20] michiel at tincan dot co dot uk
Yes, exactly.
It errors out and does nothing in the latter case.
My bug is that it doesn't error out, but does something, ie it wipes
the string. Sorry, maybe I don't get it, but I haven't been convinced
about the bogus-ness of this bug yet.
------------------------------------------------------------------------
[2003-08-12 09:06:01] [EMAIL PROTECTED]
>From the friendly manual page for preg_replace():
"If pattern is an array and replacement is a string, then this
replacement string is used for every value of pattern. The converse
would not make sense, though."
It errors out and does nothing in the latter case.
------------------------------------------------------------------------
[2003-08-12 04:12:38] michiel at tincan dot co dot uk
Well, you may have tagged it bogus, but it's no use to have a
"Warning", when the behaviour should be different. The pattern is not
matched so regardless of the (type and value of the) replacement, the
replacement should not take place. So I still think this is a bug.
------------------------------------------------------------------------
[2003-08-11 11:45:31] [EMAIL PROTECTED]
Try increasing your error_reporting level:
Warning: preg_replace(): Parameter mismatch, pattern is a string while
replacement in an array.
------------------------------------------------------------------------
[2003-08-11 09:44:55] michiel at tincan dot co dot uk
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 this bug report at http://bugs.php.net/?id=25042&edit=1