Jump to content

print & echo


JonnoTheDev

Which do you use  

19 members have voted

  1. 1. Which do you use

    • print
      2
    • echo
      17


Recommended Posts

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.

Link to comment
Share on other sites

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';

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.