|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43642 str_replace('foo', some_func(), $text) ALWAYS call some_func()
Submitted: 2007-12-20 12:05 UTC Modified: 2007-12-20 14:37 UTC
From: kampde at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.2.5 OS: debian etch
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: kampde at gmail dot com
New email:
PHP Version: OS:


 [2007-12-20 12:05 UTC] kampde at gmail dot com
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:

Actual result:
some_func() was called!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-20 14:37 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 17:01:24 2020 UTC