|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75902 str_replace should warn when misused with nested arrays
Submitted: 2018-02-01 10:19 UTC Modified: 2020-03-09 10:55 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: anonymous at yopmail dot com Assigned: nikic (profile)
Status: Closed Package: Strings related
PHP Version: Next Minor Version OS: any
Private report: No CVE-ID: None
 [2018-02-01 10:19 UTC] anonymous at yopmail dot com
str_replace works well with a string <>
or with a single-level (one-dimensional) array <>
but I have seen it misused with a multi-dimensional array <>
 in which case it does not replace anything (it is not recursive) but does not trigger any warning either (the change of behaviour between 4.3.1 and 4.3.2 comes from Bug #23654).
I would like it to at least inform us that it is being misused.

Test script:

$a = array (
  0 => 
  array (
    'one' => 'A {bad} thing.',
    'two' => 'So far so {bad}.',
  1 => 
  array (
    'one' => 'A {bad} thing, bis.',
    'two' => 'So far so {bad}, bis.',

$b = str_replace('{bad}', 'good', $a);

echo '$b = ';
echo ';', "\n";

Expected result:
Some notice about str_replace being misused (while keeping the result untouched).

Actual result:
No notice at all. $b is identical to $a (untouched).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-09 10:39 UTC] anonymous at yopmail dot com
Would some dev please care to comment? It is even more inconsistent as preg_replace wasn't affected by the "fix" of Bug #23654 (see <>)...
 [2020-03-09 10:55 UTC]
-Assigned To: +Assigned To: nikic
 [2020-03-10 15:52 UTC]
Automatic comment on behalf of
Log: Fixed bug #75902
 [2020-03-10 15:52 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 22:01:30 2024 UTC