P粉6271364502023-08-01 14:31:16
I like <?=$whatever?> too much to give it up. I've never had a problem. I'll keep using it until it gives me trouble. Seriously, 85% of (my) clients have access to php.ini to enable them on rare occasions. The other 15% use major hosting providers, and almost all of them have enabled them. I like them.
P粉9905682832023-08-01 09:06:21
Must clearly distinguish between PHP short tags (<?) and abbreviated echo tags (<?=).
The former is prohibited in the PHP coding specification, mostly out of common sense, as this would bring problems if you need to move your code to a server that doesn't support short tags (and can't enable it) A lot of trouble. As you said, many shared hosts support short tags, but not all. If you want to share your script, it's best to use the full syntax.
The abbreviated echo tag <?= cannot be disabled, so it can be used completely.
I agree that <? is easier for programmers than <?php, but batch find and replace is possible as long as you use the same form each time.
I don't think readability is a reason. Syntax highlighting options are available to most serious developers.
As ThiefMaster mentioned in the comments, as of PHP 5.4, the <?= ... ?> tag is supported everywhere, regardless of the short tag setting. This means they are safe to use in portable code, but it also means there is a dependency on PHP 5.4. If you want to support versions before 5.4 and the use of short tags cannot be guaranteed, you still need to use <?php echo ... ?>.
In addition, you need to know that in PHP 7, the ASP tags <%, %>, <%= and script tags are removed. So if you want to support long-term portable code and want to switch to the most modern tools, consider changing these parts of your code.