php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23788 *_replace() clobbers referenced array elements
Submitted: 2003-05-24 01:06 UTC Modified: 2003-05-25 16:49 UTC
From: [email protected] Assigned:
Status: Closed Package: Strings related
PHP Version: 4.3.2RC4 OS: any
Private report: No CVE-ID: None
 [2003-05-24 01:06 UTC] [email protected]
Here's a simple test case.

--TEST--
--FILE--
<?php
$numeric = 123;
$bool = true;
$foo = array(&$numeric, &$bool);
var_dump($foo);
str_replace("abc", "def", $foo);
var_dump($foo);
?>
--EXPECT--
array(2) {
  [0]=>
  &int(123)
  [1]=>
  &bool(true)
}
array(2) {
  [0]=>
  &int(123)
  [1]=>
  &bool(true)
}

While the actual output is

array(2) {
  [0]=>
  &int(123)
  [1]=>
  &bool(true)
}
array(2) {
  [0]=>
  &string(3) "123"
  [1]=>
  &string(1) "1"
}

IMO this is not the intended behaviour, but also looks like a WFX issue. Note that the same applies to preg_replace() / ereg_replace().

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-25 16:49 UTC] [email protected]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

Fixed in 5.0 branch, waiting for feedback before MFB to 4.3 branch.
 [2003-06-16 05:59 UTC] mibra2001 at msn dot com
Information about php
 [2003-06-28 05:43 UTC] zhenxing at public dot szptt dot net dot cn
php not support utf-8 encoded document.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Dec 26 03:00:01 2025 UTC