if I enable short tag = true, then I can use like below
=$variableName ?>
Instead of
To be 100% sure that a variable will be correctly printed out on all servers where your code might possibly run, use <?php echo $variableName; ?>
. I personally always use this method.
However, if you're working on a personal project or on a simple project where you know that you will have access to php.ini or where you're not planning to move to another server, then you can safely use it.
Additionaly, <?=
is allowed by default on PHP 5.4 and above, which means all currenttly support versions of PHP support this. From php.net regarding the short_open_tag:
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.
So, in short, answer to your three questions:
But as mentioned above, if you'll be running the code only on servers with supported versions of PHP, then you can safely use it.
It not a good practice. Why i said like that because let say you want to push your code to production and you are using shared hosting. In PHP 5.4.0 above php short tags enabled by default. What if the shared hosting use the older PHP version. Some shared hosting you cannot override php.ini settings. If you want to use php shorttags you must enable it on php.ini. Refer the link below. The PHP short tag also can conflict with XML code .
http://php.net/manual/en/ini.core.php#ini.short-open-tag
No server dependency
It totally not depend on framework.
It is not bad practice, per se. New versions of PHP have it enabled, but older versions may or may not have it enabled. So, if you want everyone to be able to run your code then you should go with <?php
. If you do not care about older versions of PHP (i.e. no backwards compatibility concerns) then... do as you like.
No server dependencies. You just need to enable it.
Frameworks generally have guidelines for contributors. Which one you use personally has nothing to do with the framework, however; it has to do with if it is enabled or not.
Short tags <? doSomething(); ?>
are considered to be a bad practice because they are not XML compliant... whether you care about that or not is another issue.
Short echos <?= $myString ?>
are not a bad practice, it's just not the best. PHP is a templating engine, however much better engines are available (Twig, Mustache, Smarty, etc). Most frameworks include their own templating engine so short tags don't need to be used.
Up to and including PHP 5.3, these types of tags were considered to be the same thing. Since PHP 5.4 however they've been separated out and short echo is allowed without enable-short-tags
being turned on. Since PHP 5.3 is no longer supported, the only concern is if you're being forced to use an unsupported version, which obviously has it's own implications. :)