I've just installed apache 2.2.22, php 5.3.15 and some other stuff on my Windows 7. At some point, the tag <? stopped working (apache now returns <? ..... ?> as plain HTML). After wasting a lot of time, I noticed that the full version of this tag <?php does work! How can I fix it without editing the code?
4 Answers
You must enable php short tags for <? and <?= to work in PHP < 5.4. Call ini_set('short_open_tag', true) or modify your php.ini if you can to specify it. Some hosts even allow a php.ini within the directory of the php script itself or you can customize your php.ini through your hosting panel.
3 Comments
Paolo Bergantino
As of PHP 5.4,
<?= is always available regardless of what short_open_tag is set to.Chris McKnight
Yes, I know that but in his question he said "I've just installed apache 2.2.22, php 5.3.15 and some other stuff on my Windows 7."
Paolo Bergantino
I understand, I just left the comment because in a vacuum your opening sentence is not true anymore and I don't want anyone stumbling across your answer in the future to get the wrong idea.
Using just <? ?> is bad practice so use <?php ?> or edit short_open_tag in your php.ini file.
3 Comments
Chris McKnight
Not necessarily. Most hosts now allow some form of overriding so server compatibility does not remain an issue. There are also one-off cases where it creates an error, i.e. when outputting xml inside of a php template.
Chris McKnight
Yes it depends on the person's views but there is nothing wrong with short tags. In fact it reduces the amount of typing you have to do. The side effects are very mimimal and if you use SCM you can include the php.ini file or even use php_value inside of htaccess
Chris McKnight
True except it's a feature of PHP so it's still technically correct hehe Feature or bug?
<?php:)