note 78545 deleted from function.str-replace by felipe

From: Date: Sun, 23 Mar 2008 23:06:30 +0000
Subject: note 78545 deleted from function.str-replace by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137427@lists.php.net to get a copy of this message
Note Submitter: Hayley Watson ---- 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.

« previous php.notes (#137427) next »