From: jimflug2222 at hotmail dot com Operating system: GNU/Linux PHP version: 5CVS-2003-06-21 (dev) PHP Bug Type: Strings related Bug description: str_replace count functionality
Description: ------------ I tried out the new fourth parameter in str_replace to count the number of replacements made (this was using the very latest snapshot), and found that the fourth parameter only works if the variable passed is set already. Reproduce code: --------------- Interactive mode enabled $string = "He had had to have had it"; $newstring = str_replace("had", "foo", $string, $count); print "$count changes were made.\n"; changes were made. $count = 0; $newstring = str_replace("had", "foo", $string, $count); echo $count; 3 (Note: due to ambiguity in the manual, I tried using $count and &$count as I wasn't sure which was correct - both failed to work) Expected result: ---------------- I would have expected either a warning, "Unknown variable $count", or, otherwise, for PHP to create $count and set it to the right value. Actual result: -------------- $count didn't get set -- Edit bug report at http://bugs.php.net/?id=24281&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=24281&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=24281&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=24281&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=24281&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=24281&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=24281&r=support Expected behavior: http://bugs.php.net/fix.php?id=24281&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=24281&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=24281&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=24281&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24281&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=24281&r=dst IIS Stability: http://bugs.php.net/fix.php?id=24281&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=24281&r=gnused