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

From: Date: Mon, 21 Dec 2015 07:33:37 +0000
Subject: Bug #71178 [Opn->Ver]: 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-198078@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: requinix@php.net Reported by: pglewis13 at gmail dot com -Summary: preg_replace: non-zero array keys for pattern/replace do not work and break BC +Summary: preg_replace with arrays creates [0] in replace array if not already set -Status: Open +Status: Verified Type: Bug Package: PCRE related Operating System: Linux -PHP Version: 7.0.1 +PHP Version: 7.0.0 Block user comment: N Private report: N New Comment: 5.x unaffected. https://3v4l.org/Zhf6v Previous Comments: ------------------------------------------------------------------------ [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 (#198078) next »