JonnoTheDev Posted May 17, 2011 Share Posted May 17, 2011 Out of interest I would like to know what the members of this board prefer to use in their php. I do not want posts on the differences between print & echo because I already know all that. I use 'print' because it does what it says on the tin. It prints something to the screen. Echo is something that happens when you shout in a cave! I think I can predict that 'echo' will come out on top, but it's interesting to find out why. Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/ Share on other sites More sharing options...
Pikachu2000 Posted May 17, 2011 Share Posted May 17, 2011 I use echo. Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216479 Share on other sites More sharing options...
Philip Posted May 17, 2011 Share Posted May 17, 2011 I use echo Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216482 Share on other sites More sharing options...
Maq Posted May 17, 2011 Share Posted May 17, 2011 Echo, less typing. Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216490 Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2011 Share Posted May 17, 2011 Echo, because I like to use comma separated arguments, which also allows the Ternary operator to be used in the statement. Works as expected - echo 'some text ', isset($var) ? 'set' : 'not set', ' more text'; Doesn't work as expected - print 'some text ' . isset($var) ? 'set' : 'not set' . ' more text'; Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216505 Share on other sites More sharing options...
JonnoTheDev Posted May 17, 2011 Author Share Posted May 17, 2011 OK thats fair, never thought of that. However, for clarity, I would write that statement with either print or echo as: print 'some text ' . (isset($var) ? 'set' : 'not set') . ' more text'; Echo, less typing. Come on.. lol Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216524 Share on other sites More sharing options...
matthew9090 Posted May 17, 2011 Share Posted May 17, 2011 i use echo Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216527 Share on other sites More sharing options...
spiderwell Posted May 17, 2011 Share Posted May 17, 2011 i would like to echo the other members sentiments Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216546 Share on other sites More sharing options...
salathe Posted May 17, 2011 Share Posted May 17, 2011 I use echo mostly because it does what it says in the manual, and is less typing (both in terms of number of characters and ability to mash the keyboard and get the right sequence of them) and I like shouting in caves. Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216548 Share on other sites More sharing options...
JonnoTheDev Posted May 17, 2011 Author Share Posted May 17, 2011 ok, I thought I would be the only 'print'er i'm from the generation where 10 print "This gets printed on the screen" 20 print "echo, echo, echo" 30 goto 20 Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216724 Share on other sites More sharing options...
Philip Posted May 17, 2011 Share Posted May 17, 2011 ... 30 goto 20 Ewww... goto! Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216744 Share on other sites More sharing options...
.josh Posted May 18, 2011 Share Posted May 18, 2011 ok, I thought I would be the only 'print'er i'm from the generation where 10 print "This gets printed on the screen" 20 print "echo, echo, echo" 30 goto 20 I grew up with print as well. Having said that, I prefer echo for no particular reason. Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216759 Share on other sites More sharing options...
.josh Posted May 18, 2011 Share Posted May 18, 2011 I lied. I actually used print up until about 5m ago when I read salathe prefers echo. So I chose echo because I'm totally stalking salathe. Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216761 Share on other sites More sharing options...
DavidAM Posted May 18, 2011 Share Posted May 18, 2011 When I started using PHP, I used echo. But lately, I've been using print() for most output. Mostly because I now lean heavily on printf and sprintf, which makes it easier to see what data is being injected into the print string. Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216788 Share on other sites More sharing options...
JonnoTheDev Posted May 18, 2011 Author Share Posted May 18, 2011 When I started using PHP, I used echo. But lately, I've been using print() for most output. Mostly because I now lean heavily on printf and sprintf, which makes it easier to see what data is being injected into the print string. yes, good boy! there is no echof() is there! Get your vote on then at the top of the page. Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216895 Share on other sites More sharing options...
JonnoTheDev Posted May 18, 2011 Author Share Posted May 18, 2011 ... 30 goto 20 Ewww... goto! and 'gosub', what about that one Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216896 Share on other sites More sharing options...
spiderwell Posted May 18, 2011 Share Posted May 18, 2011 GOTO 65535 Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1216979 Share on other sites More sharing options...
ignace Posted May 18, 2011 Share Posted May 18, 2011 Whether I use print or echo depends on what I want to do (whoohoo for consistency!). I use print() whenever I echo () a single value/variable and echo() when I mix text/ternary-operator with variables using the comma to separate them instead of the dot (I type on azerty , is easier then . to write) I demand a new option in the poll: both Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1217162 Share on other sites More sharing options...
Adam Posted May 18, 2011 Share Posted May 18, 2011 I use both too, but I wrap them in a function and pass in constants I define at the top of every page to tell it which to use: define('PRINTORECHO_PRINT', 'print'); define('PRINTORECHO_ECHO', 'echo'); function printOrEcho($str, $func) { // can't be too careful if ($func == 'print' || $func == 'echo') { call_user_func($func, $str); } } printOrEcho('Hello', PRINTORECHO_PRINT); It's a little more code, but I like to type. You guys can use it if you want..? Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1217202 Share on other sites More sharing options...
ignace Posted May 18, 2011 Share Posted May 18, 2011 I rather roll my own then function o($str) { return file_put_contents('php://stdout', $str); } Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1217218 Share on other sites More sharing options...
JonnoTheDev Posted May 18, 2011 Author Share Posted May 18, 2011 not allowed! Quote Link to comment https://forums.phpfreaks.com/topic/236624-print-echo/#findComment-1217256 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.