Welcome Guest, Not a member yet? Register   Sign In
Overhead of echo?
#11

[eluser]TheFuzzy0ne[/eluser]
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?
#12

[eluser]slowgary[/eluser]
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.
#13

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

Here's another interesting one (the difference between echo and print):
Code:
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
#14

[eluser]slowgary[/eluser]
Please, allow me. I've been dying to do this for someone.
http://tinyurl.com/kjb29l
#15

[eluser]Dam1an[/eluser]
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
#16

[eluser]wiredesignz[/eluser]
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.
Code:
//require_once(APPPATH.'libraries/MY_Controller'.EXT);
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.
Code:
(1 == 1) ? echo 'TRUE' : NULL;  //parse error
(1 == 1) ? print 'TRUE' : NULL;




Theme © iAndrew 2016 - Forum software by © MyBB