#25042 [Bgs]: pattern emtpy and replacement array

From: Date: Tue, 12 Aug 2003 09:12:38 +0000
Subject: #25042 [Bgs]: pattern emtpy and replacement array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-45774@lists.php.net to get a copy of this message
ID: 25042 User updated by: michiel at tincan dot co dot uk 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: 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. Previous Comments: ------------------------------------------------------------------------ [2003-08-11 11:45:31] sniper@php.net 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

« previous php.bugs (#45774) next »