#43642 [Opn->Bgs]: str_replace('foo', some_func(), $text) ALWAYS call some_func()

From: Date: Thu, 20 Dec 2007 14:37:20 +0000
Subject: #43642 [Opn->Bgs]: str_replace('foo', some_func(), $text) ALWAYS call some_func()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120774@lists.php.net to get a copy of this message
ID: 43642 Updated by: felipe@php.net Reported By: kampde at gmail dot com -Status: Open +Status: Bogus Bug Type: Performance problem Operating System: debian etch PHP Version: 5.2.5 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Previous Comments: ------------------------------------------------------------------------ [2007-12-20 12:05:33] kampde at gmail dot com Description: ------------ In str_replace(), if you put as a replace string a call to a function (that returns a string), this call is executed always, even if the text to be replaced is not found in the text. Reproduce code: --------------- function some_func() { echo "some_func() was called!\n"; return 'bar'; } echo str_replace('foo', some_func(), "aaaaa"); Expected result: ---------------- aaaa Actual result: -------------- some_func() was called! aaaa ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43642&edit=1

« previous php.bugs (#120774) next »