php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #106 output from functions printed in wrong order
Submitted: 1998-02-26 00:35 UTC Modified: 1998-02-26 00:52 UTC
From: eric at generation-i dot com Assigned: rasmus (profile)
Status: Closed Package: Parser error
PHP Version: 3.0 Latest CVS OS: linux 2.0.33
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 - 12 = ?
Subscribe to this entry?

 
 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-02-26 00:52 UTC] rasmus
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC