Why people can use both <?
and <?php
? Why are they different ? What are the use cases for both (if there is any) ?
-
1http://php.net/manual/en/language.basic-syntax.phptags.php – Getz May 20 '14 at 09:08
-
see http://stackoverflow.com/questions/1808365/difference-between-php-and – Satish Sharma May 20 '14 at 09:11
-
1As a PHP novice, this was the first question that pointed me to "short tags". Thanks for asking the question! – Arel Apr 21 '15 at 19:22
2 Answers
<?
is a short tag. They are designed to save a few keystrokes, but are more trouble than they are worth (e.g. interfering with the XML declaration) and are turned off by default in recent versions of PHP. Don't use them.
<?php
is the normal way to switch from "dump code to STDOUT" to "execute code" mode.

- 914,110
- 126
- 1,211
- 1,335
<?
is short tag for <?php
. You can use both of them as per you feel comfortable to use one of them.
However I will recommend you to stick to <?php
as it is the industry standard.
Now comes the question of how to enable them:
You first need to specify it in your PHP.ini (settings) that whether you want to use it or not.
Modify short_open_tag=On
in your php.ini file and then restart your apache server.
If you are using a shared hosting over the internet, you cannnot edit php.ini file as they do not give access to it. But you can still solve the problem using .htaccess
. Just add this code to your .htaccess file:
php_value short_open_tag 1
.
- Source: www.PHPonwebsites.com

- 170,088
- 45
- 397
- 571

- 404
- 1
- 6
- 20