In response to php at azulmx dot com's comment
(03-10-2007):
"If your replace string results from an expression or a
function, str_replace will evaluate/call it even if the
search string is not found."
This is true for ANY function, not just str_replace: the
argument expressions are evaluated, and the results are then
passed to the function being called.
<?php
$result = str_replace ("zzz", am_i_called (),
"this string does not contain the search string");
?>
Is functionally identical to
<?php
$search = "zzz";
$replace = am_i_called();
$string = "this string does not contain the search
string";
$result = str_replace($search, $replace, $string);
?>
(except of course for the use of three additional
variables!)
This is the main reason why the comma operator is shown as
having such low precedence - everything around them has to
be evaluated first. And with the parentheses around the
argument list, those arguments are evaluated first before
the expression that contains the parenthesised expression
(i.e., the function call) can be evaluated.
----
Server IP: 203.89.181.186
Probable Submitter: 60.234.168.92
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master
.php.net/note/edit/78545
Del: integrated -- h
ttps://master.php.net/note/delete/78545/integrated
Del: useless -- http
s://master.php.net/note/delete/78545/useless
Del: bad code -- htt
ps://master.php.net/note/delete/78545/bad+code
Del: spam -- https:/
/master.php.net/note/delete/78545/spam
Del: non-english --
https://master.php.net/note/delete/78545/non-english
Del: in docs -- http
s://master.php.net/note/delete/78545/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78545
Reject -- https://mast
er.php.net/note/reject/78545
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|