Is there any particular reason to use one over the other? I personally tend to use the latter, as it just seems to flow better to me.
+12
A:
They do the same thing, the <?= is just called the short tag and is shorthand for <?php echo. You have to make sure the short tags are enabled to use the <?= notation.
Brian Fisher
2009-01-12 19:36:13
It's also not compatible with XML-based docs (like Xhtml), since XML requires '<?' for it's own use. Long tags '<?php' are compatible, and highly recommended for portability.
Alister Bulman
2009-01-13 00:14:56
As the php.ini.dist files says: "NOTE: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server....."
Alister Bulman
2009-01-13 00:15:57
+3
A:
As far as I know, they are functionally equivalent except the second can be disabled in configurations so isn't as portable.
Rob Prouse
2009-01-12 19:36:26
A:
The shorthand is clearer. It says, with as few words possible:
"Here, an expressions is echoed and nothing else is going on."
PEZ
2009-01-12 20:14:17
A:
Short tags are disabled on a significant amount of php installation so I never use
<?=$my_var?> // Bad Portability
<?php echo $my_var; ?> // Good Portability!
Mike B
2009-01-12 21:57:20
A:
Just an addon question. I've read a few years ago that using <?
and ?>
is not recommended due to security issues. Is this correct?
rebellion
2010-03-19 10:43:34