Reputation: 8212
I have some php variables that I need to spit out in a template file.
Normally I would do <?php echo $var; ?>
But I know you can also do <?=$var?>
and it will do the same thing.
I know I've seen a setting for "enable php shorttags" or something like that. Meaning that the server will interpret both <?
and <?php
My question is, do shorttags have to be allowed in order to the method of getting vars <?=$var?>
?
Thanks!
Upvotes: 1
Views: 251
Reputation: 20446
From the manual:
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. For portable, redistributable code, be sure not to use short tags.
Also,
This directive also affected the shorthand
<?=
before PHP 5.4.0, which is identical to<? echo
. Use of this shortcut required short_open_tag to be on. Since PHP 5.4.0,<?=
is always available.
Upvotes: 0
Reputation: 7490
The answer is yes for versions of PHP prior to 5.4.0:
Note: This directive also affected the shorthand
<?=
before PHP 5.4.0, which is identical to<?
echo. Use of this shortcut required short_open_tag to be on. Since PHP 5.4.0,<?=
is always available.
Upvotes: 0
Reputation: 160933
Since PHP 5.4.0, <?=
is always available. Before that, short_open_tag have to be allowed to using this.
Upvotes: 0
Reputation: 360842
Yes, short tags is required for <?=
. People hate on short tags regularly, under the mantra of "your code won't be portable. the new server might not have them enabled!". So... if you're going for portability, avoid short tags. If you can guarantee the operating environment and can turn them on, then feel free to use them.
Upvotes: 0
Reputation: 163548
It depends on the PHP version.
As of 5.4.0, <?=
always works. Prior to that, short_open_tag
needs to be enabled in PHP.ini.
See also: http://php.net/manual/en/ini.core.php
I'd avoid using them, for maximum portability.
Upvotes: 5