0

My Apache/PHP installation is making me use <?php ... ?> instead of <? ... ?>. Where is this found in the configuration file so that I don't need to do the former? I'm assuming it's in php.ini, but not sure what it would be called.

4
  • 11
    Wouldn't it be worth getting in the habit of using the canonical opening tag anyway, so that your code is 100% portable? Commented May 10, 2010 at 0:06
  • 3
    To explain what @chibeneku means, the <? short open tag is not valid in XML or XHTML, so it breaks some developer tools that test for valid web page markup. Because of this, lots of people consider it better practice to continue using the <?php longer open tag. Commented May 10, 2010 at 0:14
  • Also, questions related to short open tags pop up all the time on Stack Overflow. The answer is probably already here in a similar question. Commented May 10, 2010 at 0:16
  • 1
    Not everything needs to be portable. As long as you realize that you need to have control over the settings of the server on which your code runs there's nothing wrong with using short open tags if that's what you prefer. Advantages like using <?=$variable;?> and clean and simple syntax like stackoverflow.com/questions/2795847/… are a big plus. Commented May 10, 2010 at 11:18

4 Answers 4

5

It's the short_open_tag configuration directive. http://php.net/manual/en/ini.core.php

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, and yes I understand the portability thing - but I just redid my server and have tons of old stuff with those style tags. But going forward - good idea :)
In that case it may be better to use a .htaccess file and set the short_open_tag for your legacy code, but keep your server correctly configured to ensure maximum portability for your code.
4

It is defined in php.ini as short_open_tag.

Keep in mind however, for maximum portability, stick with <?php ... ?>. You have just proved to yourself how unreliable it is to rely on short tags being enabled. You wouldn't want to show the world your PHP source if it made its way onto a short tag disabled server would you?

I've also read, but can not confirm, that short tags will be removed in newer versions of PHP.

Comments

3

Definitely keep using <?php instead of <?, it's good practice and it makes your code more readily mobile for other projects and websites that may have short_open_tag enabled or disabled.

Comments

1

The option is called short_open_tag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.