note 78545 added to function.str-replace

From: Date: Tue, 16 Oct 2007 23:34:58 +0000
Subject: note 78545 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-131438@lists.php.net to get a copy of this message
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 -- https://master.php.net/note/delete/78545/integrated Del: useless -- https://master.php.net/note/delete/78545/useless Del: bad code -- https://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 -- https://master.php.net/note/delete/78545/in+docs Del: other reasons-- https://master.php.net/note/delete/78545 Reject -- https://master.php.net/note/reject/78545 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131438) next »