note 78898 added to function.echo
| From: | nikolaas dot mennega at links dot com dot au | Date: | Thu, 01 Nov 2007 07:04:45 +0000 |
| Subject: | note 78898 added to function.echo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131901@lists.php.net to get a copy of this message | ||
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:
<?
echo "outside func ()\n", func ();
?>
effectively becomes:
<?
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:
<?
echo "outside func ()\n" . func ();
?>
effectively becomes:
<?
//func ()
{
echo "within func ()\n";
}
echo "outside func ()\n" . '';
?>
----
Server IP: 203.16.234.20
Probable Submitter: 202.168.17.7
----
Manual Page -- http://www.php.net/manual/en/function.echo.php
Edit -- https://master.php.net/note/edit/78898
Del: integrated -- https://master.php.net/note/delete/78898/integrated
Del: useless -- https://master.php.net/note/delete/78898/useless
Del: bad code -- https://master.php.net/note/delete/78898/bad+code
Del: spam -- https://master.php.net/note/delete/78898/spam
Del: non-english -- https://master.php.net/note/delete/78898/non-english
Del: in docs -- https://master.php.net/note/delete/78898/in+docs
Del: other reasons-- https://master.php.net/note/delete/78898
Reject -- https://master.php.net/note/reject/78898
Search -- https://master.php.net/manage/user-notes.php