Are PHP Short Tags Acceptable to Use?
Despite their convenience, it's generally advised against using PHP short tags ( and ?>) due to portability issues.
Why They're Not Recommended
Short tags are not consistently supported across different servers. While many shared hosts enable them, it's not a guarantee. This creates problems if you need to move your code to a server that does not support short tags.
In addition, the PHP Coding Standard prohibits the use of the short tag because it can lead to confusion in situations where = and are used together.
Shorthand Echo Tag vs. Short Tag
It's important to note the distinction between the short tag () and the shorthand echo tag (=) which is fully acceptable to use. The shorthand echo tag is supported everywhere and cannot be disabled, making it a portable and reliable option.
Conclusion
While short tags may offer a slight convenience, the potential for portability issues and coding standard violations outweighs that benefit. It's best practice to use the full syntax () to ensure code compatibility and readability.
The above is the detailed content of Should I Use PHP Short Tags?. For more information, please follow other related articles on the PHP Chinese website!