Using short versus long form of PHP open close tags
PHP code in HTML document is sectioned off by PHP opening and closing tags as shown here…
There is the question whether to use the long form as shown above versus using the short form as shown below…
In my case, both works and outputs “Hello World” to the browser. That is because my server is set with short_open_tag set to “On” in the php.ini as seen when phpinfo() is invoked. The short form of PHP open/close tags only works when that is the case, or if PHP was configured with the –enable-short-tags option.
But the long form works all the time. Hence the long form is preferred. PHP.net even says that short form is “discouraged”.
When using the short form, it can be ambiguous if you have inline-xml declaration somewhere in your code such as …
<?xml version="1.0"?>
As you can see, that xml declaration also starts with the same two characters as the PHP short tag — browser and yourself can both get confused.
The only advantage of using the short form is that the short form of echo can be used as in …
If the file is a pure PHP file, the closing PHP is preferred to be omitted.