|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-06-23 09:34 UTC] stas@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 17:00:01 2025 UTC |
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