Page 1 of 1

= / echo

Posted: Tue Apr 13, 2004 11:57 am
by mrvanjohnson
Is this considered "sloppy code"

Code: Select all

<?=$variable?>
Compared to

Code: Select all

<?php echo $variable ?>
Working on a project I think I might release in Sourceforge and I just want to have the most compatiable, cleanest code. Any opinions?

Posted: Tue Apr 13, 2004 12:01 pm
by kettle_drum
I would personally consider <?php echo $variable; ?> to be the neatest and easiest to read and understand.

Posted: Tue Apr 13, 2004 12:31 pm
by MarK (CZ)
Both work same. Maybe you need ';' in the second command, I'm not sure here. But I use the first one very often.

Posted: Tue Apr 13, 2004 12:31 pm
by magicrobotmonkey
Hmm. i never heard of that first one

Posted: Tue Apr 13, 2004 12:40 pm
by redmonkey
The first one is only supported if 'short open tags' is enabled in your php config.

Personally I always use the later as you never know what server config you are going to come across.

I wouldn't consider it sloppy coding but I would consider it to be less portable than your comparison.

Posted: Tue Apr 13, 2004 1:56 pm
by mrvanjohnson
Thanks everyone. Especially redmonkey, that was exactly the answer I was looking for.

Just FYI magicrobotmonkey, <?= is PHP short hand for <?php echo :-)

Posted: Tue Apr 13, 2004 2:02 pm
by magicrobotmonkey
Yea I just checked it out in the manual. Guess its a good way to save a few keystrokes...

Posted: Tue Apr 13, 2004 4:49 pm
by mudkicker
I use the 1st one but what redmonkey says is right.
I think you should use the 2nd, if you release it on SourceForge.

Posted: Tue Apr 13, 2004 6:10 pm
by vigge89
i only use the first one when just echoing small blocks, like an small echo-statement in HTML

Posted: Tue Apr 13, 2004 6:26 pm
by andre_c
It is recommended not to use use the shorthand way if you're dealing with XML since it uses the same "<?"