The cart is empty

PHP is a scripting language widely used for web application development. One of the options PHP offers is the use of the short_open_tag directive in the php.ini configuration file. This directive allows programmers to use the shorthand <? instead of the standard <?php to open a PHP block.

How short_open_tag works

The standard way to start a block of PHP code is to use <?php. This syntax is always safe and works regardless of configuration settings. On the other hand, short_open_tag allows you to start a PHP block simply by using <?, which can be faster and more readable for some developers. If short_open_tag is active, you can also use <?= as a shortcut for <?php echo.

Why you should or should not use short_open_tag

Using short_open_tag can increase the speed of writing code and its readability, especially in templates where it is often necessary to output values. However, there are reasons why you should be careful:

  1. Code Portability: Not all hosting servers have short_open_tag enabled. Code that uses <? may fail on some servers.

  2. Standardization: PHP-FIG and PSR standards recommend using <?php for better readability and uniformity of code.

  3. XML Conflict: <? can collide with XML tags like <?xml, which can lead to errors in processing XML.

How to enable or disable short_open_tag

To change the short_open_tag setting, you need to modify the php.ini file:

  1. Find the php.ini file in your PHP environment.
  2. Find the line short_open_tag = Off or short_open_tag = On.
  3. Change the value to On to enable or Off to disable.
  4. Restart your web server to apply the changes.

 

Using short_open_tag can be convenient for some developers, but it is important to consider potential portability and standardization issues. It is recommended to adapt to standard practices and use the full form <?php to make your code more robust and compatible across different environments.