[thelist] php form

Dougal Campbell dougal at gunters.org
Fri Nov 22 14:04:01 CST 2002


On Fri, 22 Nov 2002, MarsHall wrote:

> On Friday, Nov 22, 2002, at 10:54 US/Central, Dougal Campbell wrote:
> > For the most part, there's no differences. But there are a few *subtle*
> > differences where print will work, and echo will not. See the PHP
> > manual
> > for details and examples:
> >   http://www.php.net/manual/en/function.echo.php
> >   http://www.php.net/manual/en/function.print.php
>
> In fact, there currently is NO DIFFERENCE between print() and echo().
> The subtle difference you speak of is in regards to Variable Functions,
> which is actually an error in the PHP documentation! See:
> http://bugs.php.net/bug.php?id=16739
>
> They are synonyms for the same construct. Your choice. Consistency in
> your own code should be top priority. So, pick one and stick to it.
>
> Also, both echo and print function without parenthesis around their
> argument.

That error is different from what makes them different. Check the end of
the examples for "echo":

  // Because echo is not a function, following code is invalid.
  ($some_var) ? echo('true'): echo('false');

  // However, the following examples will work:
  ($some_var) ? print('true'): print('false'); // print is a function
  echo $some_var ? 'true': 'false'; // changing the statement around

I checked this on my server (running PHP 4.2.3), and using echo within
the ternary operator does indeed throw an error, whereas print works
just fine.

See also:
  http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40

So, at least in PHP 4.2.x, the implementations for echo and print are
*not* exactly the same. The miniscule speed gain you might get with echo
would probably only matter if you were using it to print *many* lines of
output in a loop. And print is a little more flexible since it behaves
more like a real function.

--
Ernest MacDougal Campbell III, MCP+I, MCSE <dougal at gunters.org>
http://dougal.gunters.org/             http://spam.gunters.org/
  Web Design & Development:  http://www.mentalcollective.com/
       This message is guaranteed to be 100% eror frea!




More information about the thelist mailing list