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

From: Date: Mon, 21 Dec 2015 10:11:10 +0000
Subject: Bug #71178 [Ver->Csd]: preg_replace with arrays creates [0] in replace array if not already set
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198084@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71178&edit=1 ID: 71178 Updated by: laruence@php.net 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 laruence@gmail.com 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] requinix@php.net 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

« previous php.bugs (#198084) next »