Req #75902 [NEW]: str_replace should warn when misused with nested arrays
| From: | anonymous at yopmail dot com | Date: | Thu, 01 Feb 2018 10:19:25 +0000 |
| Subject: | Req #75902 [NEW]: str_replace should warn when misused with nested arrays | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213776@lists.php.net to get a copy of this message | ||
From: anonymous at yopmail dot com
Operating system: any
PHP version: Next Minor Version
Package: Strings related
Bug Type: Feature/Change Request
Bug description:str_replace should warn when misused with nested arrays
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).
--
Edit bug report at https://bugs.php.net/bug.php?id=75902&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75902&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75902&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75902&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75902&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75902&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75902&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75902&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75902&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75902&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75902&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75902&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75902&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75902&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75902&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75902&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75902&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75902&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75902&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75902&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75902&r=mysqlcfg