Req #75902 [Asn->Csd]: str_replace should warn when misused with nested arrays

From: Date: Tue, 10 Mar 2020 15:52:32 +0000
Subject: Req #75902 [Asn->Csd]: str_replace should warn when misused with nested arrays
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226011@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75902&edit=1 ID: 75902 Updated by: nikic@php.net Reported by: anonymous at yopmail dot com Summary: str_replace should warn when misused with nested arrays -Status: Assigned +Status: Closed Type: Feature/Change Request Package: Strings related Operating System: any PHP Version: Next Minor Version Assigned To: nikic Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikita.ppv@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=e8678fcb42c5cb1ea38ff9c6819baca74c2bb5ea Log: Fixed bug #75902 Previous Comments: ------------------------------------------------------------------------ [2020-03-09 10:39:18] 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 <https://3v4l.org/11lUa>)... ------------------------------------------------------------------------ [2018-02-01 10:19:23] 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). ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75902&edit=1

« previous php.bugs (#226011) next »