php.net |  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
 [2007-12-20 12:05 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-20 14:37 UTC] felipe@php.net
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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC