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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kampde at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sun Dec 22 05:01:30 2024 UTC