How to enable PHP short tags?

How to enable PHP short tags?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to Enable PHP Short Tags

If you are porting a legacy application from Linux to Windows, you might encounter the frustrating discrepancy between <? and <?php. The former is known as a short tag, while the latter is the standard long form. While modern PHP versions default to the long form for compatibility reasons, many older frameworks or scripts rely on the brevity of <? to mark the start of a script.

When you move an application that starts with <?> from one environment to another, particularly between different distributions of Linux or Windows Server, you may find that SQL statements or other dynamic content render incorrectly. This often happens because the target PHP configuration has disabled short tags by default. To restore consistency and ensure your application behaves exactly as it did on the original server, you must explicitly enable short tags in your PHP environment.

Understanding the Configuration Requirement

The core issue lies in how PHP parses files versus how it handles output buffering. By default, since PHP 5.4, the engine expects <?php or <?= to start a script. If a file begins with just <?>, PHP treats the content following it as plain text until it hits an end-of-file marker or a closing tag, effectively ignoring the intended logic unless short tags are permitted.

To enable this behavior, you need to modify the php.ini configuration file located in your server's installation directory. You must locate the directive responsible for short tag support and set it to On. The specific line you are looking for is:

short_open_tag = On

Once you have added or uncommented this line, ensure that you restart your web server. On Apache, a simple restart command usually suffices:

sudo service apache2 restart
# or
sudo systemctl restart apache2

For Nginx, since it does not handle PHP directly, you must reload the PHP-FPM service:

sudo systemctl reload php-fpm

If you are running PHP on Windows via IIS or XAMPP, navigate to your php.ini-development or php.ini-production file and make this change there. Remember that editing the configuration often requires a full restart of the web server process for changes to take effect immediately.

Trade-offs and Compatibility Considerations

Enabling short tags is straightforward, but it introduces significant compatibility risks that seasoned developers should weigh carefully. The primary pitfall is that enabling short_open_tag allows PHP to interpret any occurrence of <?> as the start of a script, even if it appears in the middle of a file or within string content.

Consider a scenario where your application contains an HTML template with a variable placeholder like this:

echo "Welcome <? $name ?>";

If short_open_tag is enabled, PHP will attempt to parse the text following <? inside that string as PHP code. This can lead to syntax errors, unexpected variable interpolation failures, or security vulnerabilities if user input triggers a script start within a string.

Furthermore, mixing short tags and long tags in the same project often leads to maintenance headaches. If one developer assumes the old standard (<?) while another uses the new standard (<?php), you risk breaking builds on different servers unless the configuration is perfectly synchronized across the entire stack.

Most modern PHP documentation recommends sticking to <?php or <?= because they are unambiguous. However, if you are maintaining a legacy system where changing every file from <?> to <?php is impractical due to sheer volume or lack of version control history, enabling short tags becomes the necessary evil for migration.

Verification Steps

After making these changes, verifying that your application works correctly is crucial. Load the specific page containing the SQL statement that was rendering differently on Windows. Check the output carefully for any unexpected HTML being displayed instead of query results. If the issue persists, inspect the error logs in both /var/log/apache2/error.log (Linux) or the Windows Event Viewer to see if PHP is throwing a syntax error regarding unclosed tags.

If you are using Laravel or other modern frameworks, be aware that they generally do not support short tags out of the box and may throw fatal errors if enabled without proper configuration. For such cases, switching to <?php in your existing files is often the safer route than trying to force short tag support.

Ultimately, enabling short tags restores parity between your Linux and Windows environments, allowing you to eliminate environment-specific bugs. Just remember that this convenience comes at the cost of reduced code clarity and increased potential for parsing errors, so use it only when necessary for legacy compatibility.

Our network