I think that I've been used to a fairly liberal policy regarding the PHP declaration in projects - I've always just used:
<? // here is my php code ?>
I just setup an nginx server using PHP-FPM under FastCGI and now it requires me to declare explicitly:
<?php // here is my php code ?>
Is there any way to change that? (Since otherwise I would have to go into my project and find/replace all of the instances where this occurs).
<?=
is always available, while short_open_tag
is off by default - Michael Berkowski 2012-04-04 18:11
You need to enable short open tags via the php.ini configuration file. However, if you are using XML concurrently with PHP, there will be a conflict.
Just found a good article on the deprecation of short tags in PHP6.
<?
with <?php
. It takes about 2 minutes.. - Radu Murzea 2012-04-04 18:25
Go into php.ini and find the option short_open_tag
. Set it to On
. This will solve your problem.
Short open tags are what you're looking for.
There is no such thing as a PHP script. There's only files that have PHP code blocks embedded in them. You MUST start a php code block with <?php
(or <?
if you've got short-tags enabled). There is no way around this. Without that opening tag, the PHP interpreter will just act as a very expensive version of 'cat'.
While the answers given are correct in how to enable short tags, I would recommend against it. Consider that the code you write may not be run solely on your computer. If you plan on distributing your code or deploying it to a production server you should always use <?php
to open the tags as this will minimize the likelihood of your code not running and the troubleshooting associated with it.