A
It is interesting to use <? rather than <?php?Not today. And honestly, I believe it never was. The tag <?php there is, at least, since version 2 of the language (some places cite that since version 1) and since then it is recommended its use. The existence of the tag <? means that it was a PHP project error in choosing a tag that was already used by a long known standard, XML. In this case, it was not possible to add raw XML code inside a PHP file because it would give syntax error:<?xml version="1.0" encoding="UTF-8"?>
<user>
<?
$arr = array("name" => "John", "age" => 99);
foreach ($arr as $field => $value)
{
echo "<" . $field . ">" . $value . "</" . $field . ">";
}
?>
</user>
In this case, the content xml version encoding="UTF-8" would be treated as PHP code and, being invalid, would generate the previously cited syntax error.Another negative point, and the main one currently, is the dependency on enabling the option short_open_tag in the file php.ini. As much as an easy-to-do change, the developer will have problems migrating its application between different servers. Each new server should be concerned about setting the correct configuration options.Use the tag <?php eliminates both problems at once, so there is no reason to use <? in the place of <?php.Note: When the file is purely PHP, it is advised not to use the closing tag ?>Because any blank space or line break after this triggers the PHP output buffer. Often this is not the behavior expected by the developer and it is a very difficult error to be debugged, especially when worked with includes of various files and there at the end you need to give the famous header("Location:"), generating even more famous error https://pt.stackoverflow.com/questions/4251/erro-cannot-modify-header-information .Is there any special functionality when using <? ?>?No, none. The functionality of both is the same. The tag <?php only exists to circumvent the above problems.What advantages and disadvantages to use <? rather than <?php?Advantage: Type 3 characters less (if your editor no longer does this for you). Disadvantages: can generate conflict with other languages such as XML and depends on server configuration. In short: use <?php.As for the use of <?= in the place of <?php echo, Is it only character savings to code?In fact, it is directly related to tag <?, so much as for versions prior to 5.4.0, when the option short_open_tag were disabled, the print tag <?= It was too. Seeing that her syntax helps a lot when displaying a PHP variable in the middle of HTML, from version 5.4.0 this tag, <?=, is always active, regardless of the option in the settings and can be used without fear.<div>Nome: <?= $nome ?></div>
It is worth remembering that the character ; after the variable, in this case, is optional and thus the above code excerpt is perfectly valid.Note: the real tagI believe it is important to make it clear that the correct tag is <?php[whitespace] and not just <?php. It seems to make no difference, but for example, the code below would not be interpreted correctly and would be shown on the screen as text:<?phpecho "Olá mundo" ?>
<?php/* comentário */ phpinfo(); ?>
If the tag was only <?php, it would work perfectly. But what is this [whitespace] Does that mean? It is any character that manages a horizontal or vertical spacing, including the blank space itself (), tab (\t) and line break (\n).ExtraOther tags that existed in PHP, such as <%, %>, <%= and <script language="php"> have been removed completely from PHP 7.0.0 and should not be used in any circumstances. References https://secure.php.net/manual/pt_BR/language.basic-syntax.phptags.php https://secure.php.net/manual/pt_BR/ini.core.php#ini.short-open-tag https://stackoverflow.com/q/4410704/1452488 https://stackoverflow.com/q/2185320/1452488 Stack Overflow: How to enable PHP short tags?