Opening php file declaration question


I've inherited an existing php web site. The file names end with the php extension and the code appears to be php.

Just wondering why the opening file declaration is "<?" instead of "<?php".

What is the difference between the 2 and why would one be used over the other.





It's called PHP short tags. If short tags is enabled the two notations are equivalent, but short tags can be disabled on some servers so it's usually best to write the tag in full in you are in doubt.

The documentation has this to say:

short_open_tag boolean

Tells whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use<?xml ?> inline. Otherwise, you can print it with PHP, for example:<?php echo '<?xml version="1.0"?>'; ?> . Also if disabled, you must use the long form of the PHP open tag (<?php ?>).




<? is 3 fewer characters to type, but will be ambiguous in an XML document (<?xml version="1.0"?> will cause a parse error) and if the short_tags setting is off, it won't work. There's also<?= as a shortcut for<?php echo




This are short tag, i recommend not to use it. There are a lot of them like <script type="php"></script> or asp like<% %> But i recommend to use the<?php ?> style :-)

People are also looking for solutions to the problem: escaping - Is it possible to "escape" a method name in PHP, to be able to have a method name that clashes with a reserved keyword?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.