note 78898 deleted from function.echo by googleguy

From: Date: Wed, 22 Jan 2014 20:55:39 +0000
Subject: note 78898 deleted from function.echo by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198315@lists.php.net to get a copy of this message
Note Submitter: nikolaas dot mennega at links dot com dot au ---- hemanman at gmail dot com, the problem is that func() doesn't actually return a value (string or otherwise), so the result of echoing func() is null. With the comma version, each argument is evaluated and echoed in turn: first the literal string (simple), then func(). Evaluating a function call obviously calls the function (and in this case executes its own internal echo), and the result (null) is then echoed accordingly. So we end up with "outside func() within func()" as we would expect. Thus: <?php echo "outside func ()\n", func (); ?> effectively becomes: <?php echo "outside func ()\n"; //func () { echo "within func ()\n"; } echo ''; ?> The dot version is different: there's only one argument here, and it has to be fully evaluated before it can be echoed as requested. So we start at the beginning again: a literal string, no problem, then a concatenator, then a function call. Obviously the function call has to be evaluated before the result can be concatenated with the literal string, and THAT has to happen BEFORE we can complete the echo command. But evaluating func() produces its own call to echo, which promptly gets executed. Thus: <?php echo "outside func ()\n" . func (); ?> effectively becomes: <?php //func () { echo "within func ()\n"; } echo "outside func ()\n" . ''; ?>

« previous php.notes (#198315) next »