PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mrvanjohnson
Forum Contributor
Posts: 137 Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA
Post
by mrvanjohnson » Tue Apr 13, 2004 11:57 am
Is this considered "sloppy code"
Compared to
Working on a project I think I might release in Sourceforge and I just want to have the most compatiable, cleanest code. Any opinions?
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Tue Apr 13, 2004 12:01 pm
I would personally consider <?php echo $variable; ?> to be the neatest and easiest to read and understand.
MarK (CZ)
Forum Contributor
Posts: 239 Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:
Post
by MarK (CZ) » Tue Apr 13, 2004 12:31 pm
Both work same. Maybe you need ';' in the second command, I'm not sure here. But I use the first one very often.
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Tue Apr 13, 2004 12:40 pm
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.
mrvanjohnson
Forum Contributor
Posts: 137 Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA
Post
by mrvanjohnson » Tue Apr 13, 2004 1:56 pm
Thanks everyone. Especially redmonkey, that was exactly the answer I was looking for.
Just FYI magicrobotmonkey, <?= is PHP short hand for <?php echo
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Tue Apr 13, 2004 2:02 pm
Yea I just checked it out in the manual. Guess its a good way to save a few keystrokes...
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Tue Apr 13, 2004 4:49 pm
I use the 1st one but what redmonkey says is right.
I think you should use the 2nd, if you release it on SourceForge.
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Tue Apr 13, 2004 6:10 pm
i only use the first one when just echoing small blocks, like an small echo-statement in HTML
andre_c
Forum Contributor
Posts: 412 Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah
Post
by andre_c » Tue Apr 13, 2004 6:26 pm
It is recommended not to use use the shorthand way if you're dealing with XML since it uses the same "<?"