Question

I have an application that has some PHP code, the PHP open/close tag I'm using is:

<? 
        $anything;
        echo problem;

?>

The application is not running.

Are there some rules for this type of open/close ( maybe a php.ini config.) that might cause the application not to run ?

P.S. Would the better way be to change all <? to <?php ?

Was it helpful?

Solution

run a phpinfo(), look for the path which php.ini is used. Then open the file and find short_open_tag

Set it to on or off.

But in general.. use <?php ?> this is better.

OTHER TIPS

Use <?php ?>. <? ?> are referred to as short-tags, and not every server is setup to support them.

The <? version of the open tag is called a "short tag." While the php community prefers the use of the full <?php version of this tag, it is still acceptable to use short tags. Ideally, we would all use <?php all the time, but we often deal with legacy code, and changing all occurrences of <? to <?php can be tedious and time consuming. If you find yourself in a situation where you need to allow the php interpreter to recognize the short tag, you may enable it in the php.ini file using the "short_open_tag=1" directive.

For new code you are developing, I would recommend using the long version of the tag <?php, as you know that will be compatible regardless of the ini setting used in the servers php.ini config. For more information on this, see: Are Php Short Tags Acceptable To Use here on StackOverflow.

To figure out why your application is not running, check the webserver error logs, as well as the php error logs, and consider turning up php's error reporting level. This can also be done in the php.ini file using the error_reporting directive. This will allow you to determine what is causing the application to not run, and then you will be more informed for further questions.

You should use <?php ?> to ensure correct parsing.

There are specific times where it is suited or possible to use the short tags like this for PHP

<?=$sign['last_connected']?>

notice the <?= instead of <?php echo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top