php.net |  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: -
From: anonymous at yopmail dot com Assigned:
Status: Open Package: Strings related
PHP Version: Next Minor Version OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-02-01 10:19 UTC] anonymous at yopmail dot com
Description:
------------
str_replace works well with a string <https://3v4l.org/oH6HQ>
or with a single-level (one-dimensional) array <https://3v4l.org/ED1hB>
but I have seen it misused with a multi-dimensional array <https://3v4l.org/tWEWt>
 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.
Thanks

Test script:
---------------
<?php

$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 = ';
var_export($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).

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 13 10:01:24 2019 UTC