• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Overhead of echo?

I just found this forum post - http://forums.invisionpower.com/topic/16...and-print/

I know it's hardly conclusive, but it sure got me thinking. Aren't print and echo both constructs?

You're right! Php.net has them both listed under string functions, but each has a note stating that they're not function but constructs (whatever that means). Either way there's a bit of overhead in calling them, so if you're not using CodeIgniter [, you're crazy and] you should use an output $buffer.

I don't really understand constructs either, but I do believe that construct can be used without parentheses.
print "something";
echo "something else";
include "some_file";

Here's another interesting one (the difference between echo and print):
echo "a string", "another string", "and another string";

I should really look into it a bit further, but I can't seem to find anything useful. It's a pity wiredesignz isn't around to Google That For Me. Wink

Please, allow me. I've been dying to do this for someone.

gary, lovin' it Smile
And yeah, echo accepts multiple paramters, which is (marginally) quicker then concatenation
I use it that way all the time now

We often see PHP constructs used like functions when in fact the parentheses only serve to identify some formula that needs to be performed on the arguments before they are processed. Constructs do not require parentheses.
require_once APPPATH.'libraries/MY_Controller'.EXT;  //is identical
the worst case is when used in return('ing'); from a function. return 'ing'; is correct;

print returns a value of 1 and echo does not. print can also be used in a ternary operator echo cannot.
(1 == 1) ? echo 'TRUE' : NULL;  //parse error
(1 == 1) ? print 'TRUE' : NULL;

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.