Click here to get back home

echo format Q

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
echo format Q Twayne 07-03-2008
|--> Re: echo format Q Michael Fesser07-04-2008
Posted by Twayne on July 3, 2008, 10:12 pm
Please log in for more thread options
Hi,

Irrelevant question time, probably:

Is there any advantage/reason to use one format over the other for the
following two types of echo statements?

1. echo "error is " . $error;
2. echo "error is $error";

Obviously I'm talking about longer statements than the samples above,
but they do create identical outputs.

Line 1 is how most of the code snippets/samples I find are written.
But line 2 is a lot less typing and for me at least, easier to keep
track of.

Maybe it's my gross inexperience showing but the only time I see the
..." . concatenator useful is if I want to print something like
"$error is 0"; then it's just echo '$error is ' . $error; but as
always, there are still other ways to accomplish it, which I didn't mean
to get into here.

If you consider this a waste of your time, OK; I understand. But if
have an opinion I'd be interested to hear whether there is any advantage
of one over the other. Mostly, so that I pick up the preferred habit if
nothing else.

TIA,

Twayne



Posted by Jerry Stuckle on July 4, 2008, 12:17 am
Please log in for more thread options
Twayne wrote:
> Hi,
>
> Irrelevant question time, probably:
>
> Is there any advantage/reason to use one format over the other for the
> following two types of echo statements?
>
> 1. echo "error is " . $error;
> 2. echo "error is $error";
>
> Obviously I'm talking about longer statements than the samples above,
> but they do create identical outputs.
>
> Line 1 is how most of the code snippets/samples I find are written.
> But line 2 is a lot less typing and for me at least, easier to keep
> track of.
>
> Maybe it's my gross inexperience showing but the only time I see the
> ..." . concatenator useful is if I want to print something like
> "$error is 0"; then it's just echo '$error is ' . $error; but as
> always, there are still other ways to accomplish it, which I didn't mean
> to get into here.
>
> If you consider this a waste of your time, OK; I understand. But if
> have an opinion I'd be interested to hear whether there is any advantage
> of one over the other. Mostly, so that I pick up the preferred habit if
> nothing else.
>
> TIA,
>
> Twayne
>
>
>

Google "Premature optimization". Then don't worry about the difference.

All a matter of style. Pick the one which suits you best. Because of
you ask 100 programmers, you'll get 25 different reasons as to which to
use and why. And you'll also get another 75 different answers as to
which is the "better" way to do it :-)

Seriously - consistency is more important in this case.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================


Posted by Michael Fesser on July 4, 2008, 7:36 am
Please log in for more thread options
.oO(Twayne)

>Irrelevant question time, probably:
>
>Is there any advantage/reason to use one format over the other for the
>following two types of echo statements?
>
>1. echo "error is " . $error;
>2. echo "error is $error";
>
>Obviously I'm talking about longer statements than the samples above,
>but they do create identical outputs.

3. echo 'error is ', $error;
4. printf('error is %s', $error);
5. ...

Use whatever you like. I prefer embedded variables or printf() if I have
to embed multiple variables or complex expressions into a string. Of
course with 2. you should use an editor with good syntax highlighting.

Micha

Posted by Twayne on July 4, 2008, 11:14 am
Please log in for more thread options
> Hi,
>
> Irrelevant question time, probably:
>
> Is there any advantage/reason to use one format over the other for the
> following two types of echo statements?
>
> 1. echo "error is " . $error;
> 2. echo "error is $error";
>
> Obviously I'm talking about longer statements than the samples above,
> but they do create identical outputs.
>
> Line 1 is how most of the code snippets/samples I find are written.
> But line 2 is a lot less typing and for me at least, easier to keep
> track of.
>
> Maybe it's my gross inexperience showing but the only time I see the
> ..." . concatenator useful is if I want to print something like
> "$error is 0"; then it's just echo '$error is ' . $error; but as
> always, there are still other ways to accomplish it, which I didn't
> mean to get into here.
>
> If you consider this a waste of your time, OK; I understand. But if
> have an opinion I'd be interested to hear whether there is any
> advantage of one over the other. Mostly, so that I pick up the
> preferred habit if nothing else.
>
> TIA,
>
> Twayne

Thanks guys; clear/concise responses there, actually . One mentioned
consistancy, which was really the root of my question I think. I know
enough to almost be dangerous now and am settling in on some "do it this
way" things after a long spiel of trying most every different way I
could find to do things; which I'm aware I didn't find all of <g>.

Thanks much, & Regards,

Twayne




Posted by Paul Lautman on July 4, 2008, 12:11 pm
Please log in for more thread options
Twayne wrote:
> Hi,
>
> Irrelevant question time, probably:
>
> Is there any advantage/reason to use one format over the other for the
> following two types of echo statements?
>
> 1. echo "error is " . $error;
> 2. echo "error is $error";
>
> Obviously I'm talking about longer statements than the samples above,
> but they do create identical outputs.
>
> Line 1 is how most of the code snippets/samples I find are written.
> But line 2 is a lot less typing and for me at least, easier to keep
> track of.
>
> Maybe it's my gross inexperience showing but the only time I see the
> ..." . concatenator useful is if I want to print something like
> "$error is 0"; then it's just echo '$error is ' . $error; but as
> always, there are still other ways to accomplish it, which I didn't
> mean to get into here.
>
> If you consider this a waste of your time, OK; I understand. But if
> have an opinion I'd be interested to hear whether there is any
> advantage of one over the other. Mostly, so that I pick up the
> preferred habit if nothing else.
>
> TIA,
>
> Twayne

Rather than
2. echo "error is $error";

you should get used to using:
2. echo "error is ";

And
1. echo "error is " . $error;

is better as:
1. echo 'error is ' . $error;



Similar ThreadsPosted
echo all the time vs echo at the end - what is faster November 5, 2005, 9:23 am
XML Format help April 2, 2008, 8:59 pm
Date format March 12, 2005, 6:48 pm
PHP documentation in pdf format? May 10, 2005, 10:43 pm
Format float May 14, 2006, 8:51 am
year in a (****) format March 27, 2007, 2:51 pm
How to format a date? January 14, 2008, 6:28 pm
DATE Format March 25, 2008, 6:28 am
PHP / MySQL time format February 16, 2005, 1:14 am
Export Results in XML Format March 17, 2005, 9:42 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap