Are PHP Short Tags Acceptable to Use?
Introduction:
PHP offers various ways to delineate its code blocks, including short tags. While their convenience may seem appealing, it's essential to understand the underlying reasons why some recommend against using them.
Answer:
The official PHP documentation advises against using short tags because they can lead to portability issues. Short tags, such as =, are not always supported across servers, making it risky to rely on them when sharing or deploying code. Additionally, some coding standards explicitly prohibit the use of short tags.
Advantages of Short Tags: Disadvantages of Short Tags: Recommendations: Future Considerations:
Despite the portability concerns, short tags offer a concise and convenient syntax. The shorthand = tag, specifically, is a direct equivalent to
Apart from portability issues, another concern with short tags is the potential for confusion. The = tag can easily be mistaken for an assignment operator, introducing a potential source of errors. Additionally, the shorter syntax may make code less readable for those unfamiliar with it.
While the use of short tags is ultimately a matter of personal preference, it's generally advisable to avoid them. The full syntax,
As of PHP 5.4, = ... ?> tags are supported universally, making them a viable option in most cases. However, for maximum portability and future-proofing, it's recommended to avoid ASP tags ,
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3