1

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!

1

5 Answers 5

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It should also be noted that PHP 5.4 is only in beta. This essentially means that short_open_tag needs to be on for any practical application.
0

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.

Comments

0

Since PHP 5.4.0, <?= is always available. Before that, short_open_tag have to be allowed to using this.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.