Bug #76944 [NEW]: 4th parameter to str_replace / str_ireplace does not work

From: Date: Fri, 28 Sep 2018 09:54:08 +0000
Subject: Bug #76944 [NEW]: 4th parameter to str_replace / str_ireplace does not work
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217257@lists.php.net to get a copy of this message
From:             een dot meel dot of dot geen dot meel at gmail dot com
Operating system: any
PHP version:      7.0.32
Package:          *General Issues
Bug Type:         Bug
Bug description:4th parameter to str_replace / str_ireplace does not work

Description:
------------
str_replace and str_ireplace have a 4th argument that should allow one
to limit the amount of replacements.

However, this 4th replacement does not work.
Furthermore, the 4th replacement MUST be a variable that is passed by
reference for some reason??

Test script:
---------------
<?php
error_reporting(1);

echo str_replace('Hel', '', 'HelHello people! Helloooo! helloo!',
1)."\n";
echo str_ireplace('hel', '', 'HelHello people!!! Helloooo! helloo!',
1)."\n";

$ct = 1;
echo str_replace('Hel', '', 'HelHello people! Helloooo! helloo!',
$ct)."\n";
echo str_ireplace('hel', '', 'HelHello people!!! Helloooo! helloo!',
$ct)."\n";

Expected result:
----------------
Hello people! Helloooo! helloo!
Hello people! Helloooo! helloo!
Hello people! Helloooo! helloo!
Hello people! Helloooo! helloo!

Actual result:
--------------
(Multiple runs, obviously)

>
PHP Fatal error:  Only variables can be passed by reference in
/opt/local/apache2/htdocs/x.php on line 4

>
PHP Fatal error:  Only variables can be passed by reference in
/opt/local/apache2/htdocs/x.php on line 5

>
lo people! loooo! helloo!
lo people!!! loooo! loo!

-- 
Edit bug report at https://bugs.php.net/bug.php?id=76944&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=76944&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=76944&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=76944&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=76944&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=76944&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=76944&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=76944&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=76944&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=76944&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=76944&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=76944&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=76944&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=76944&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76944&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=76944&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=76944&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=76944&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76944&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=76944&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=76944&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#217257) next »