|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[1998-02-26 00:35 UTC] eric at generation-i dot com
<?
cfunction test()
{
echo "-middle-";
}
?>
begin<?test()?>end<br>
<?echo "begin".test()."end<br>\n"?>
<?
$testvar=test();
echo "begin".$testvar."end<br>\n";
?>
<?
$testvar="-middle-";
echo "begin".$testvar."end<br>\n"
?>
The output from the above is:
begin-middle-test<br>
-middle-beginend<br>
-middle-beginend<br>
begin-middle-end<br>
The first and the last one are as expected but the two in the
middle are not.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 20:00:01 2025 UTC |
In order for the 'echo "begin".test()."end"' line to work as you expect, your test function should do a 'return "-middle-"' instead of echoing it directly. The behaviour you are seeing is exactly what I would expect. The function needs to be called before other output can occur on that line. For example, what if your script was: if(test()) { echo "Hello"; } Obviously the test() function needs to be called before the if condition can be evaluated. Same goes for your echo expression. The functions within the echo expression are called before the echo mechanism prints anything out. By having those functions display things directly you force this to be shown before the rest of the output.