#22141 [Csd]: str_replace hangs with extra argument

From: Date: Mon, 10 Feb 2003 19:50:54 +0000
Subject: #22141 [Csd]: str_replace hangs with extra argument
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-32677@lists.php.net to get a copy of this message
ID: 22141 Updated by: pollita@php.net Reported By: arlo@typea.net Status: Closed Bug Type: Scripting Engine problem Operating System: Mac OS 10.2 PHP Version: 4.2.3 New Comment: One more thing. It actually hadn't been removed in the 4.3 branch until just now as the method was not known to cause any actual problems and non-bug-fix changes are generally kept to the development branch. I've gone ahead and merged in the relevant portion of the changes to str_replace. PHP will now throw the customary "Incorrect Parameter Count" error if you use anything but 3 parameters with str_replace. Previous Comments: ------------------------------------------------------------------------ [2003-02-10 00:50:22] pollita@php.net This has already been fixed in CVS. PHP's internals contain two str_replace methods, the fourth parameter (when set to a non-zero value) uses the alternate search and replace method. It's not documented because the alternate method was not endoresed for use. As of 4.3.1 (which is yet to be released, you can use a snapshot from snaps.php.net in the mean time), the alternate method has been removed (and the existing method improved for speed and efficiency. ------------------------------------------------------------------------ [2003-02-09 15:15:34] arlo@typea.net I was inadvertently including a fourth argument of "-1" with some instances of str_replace() -- since I got into the habit of the limit arg using preg_replace() -- and I noticed an odd behavior: str_replace("-embed-a-", "hey", "-embed-a-", -1) returns "hey," as expected. str_replace("-embed-a-", "hey", "-embed-b-", -1) returns "embed-b-," as expected. But str_replace("-embed-a-", "hey", "-embed-aa-", -1) hangs the script until the max execution time. Removing the extraneous argument made my script work properly, but I would expect PHP to either ignore the extra argument, or return an error, rather than hanging up completely. -Arlo ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=22141&edit=1

« previous php.bugs (#32677) next »