Bug #71178 [Ver->Csd]: preg_replace with arrays creates [0] in replace array if not already set

[email protected]
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=71178&edit=1

 ID:                 71178
 Updated by:         [email protected]
 Reported by:        pglewis13 at gmail dot com
 Summary:            preg_replace with arrays creates [0] in replace
                     array if not already set
-Status:             Verified
+Status:             Closed
 Type:               Bug
 Package:            PCRE related
 Operating System:   Linux
 PHP Version:        7.0.0
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of [email protected]
Revision: http://git.php.net/?p=php-src.git;a=commit;h=817513af4ec5e5a45fdd7ecd0a00e728d00c3ff3
Log: Fixed bug #71178 (preg_replace with arrays creates [0] in replace array if not already set)


Previous Comments:
------------------------------------------------------------------------
[2015-12-21 07:33:36] [email protected]

5.x unaffected. https://3v4l.org/Zhf6v

------------------------------------------------------------------------
[2015-12-21 07:15:36] pglewis13 at gmail dot com

Description:
------------
If pattern and replace are single element arrays and the keys are non-zero integers, then preg_replace may modify the replace parameter.  In the case of the test script, the replace parameter has an empty string inserted as the 0th entry after the call to preg_replace.  

I have not tested string keys or with more than one array element.  

Test script:
---------------
https://gist.github.com/pglewis/42c7a6e3da5e465793e0

Expected result:
----------------
I could find no caveats regarding keys in the documentation, so the expectation is that the replace parameter should not be modified in any way by a call to preg_replace.  

Actual result:
--------------
An empty string is inserted into the replace parameter as an extra array element, resulting in an unexpected result and breaking backward compatibility.  


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71178&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.