# Is the PHP opening tag mandatory in byte count?

After answering the first time on PPCG on "Source code ecological footprint" I had a little discussion about it. I found it's OK if your program throws notices or warnings. But I couldn't find anything about the opening PHP tag.

My question is: Do I need to include and count it? If yes, is the short tag <? instead of <?php allowed, as it must be enabled via --enable-short-tags or php.ini?

In any case, could somebody please add an explanation in their answers on why it is needed or not? I think this might be useful for other users as well as currently all different versions can be found here in PHP answers.

Interesting read as well: Running PHP with -r instead of code tags. If a program is run from the command line using -r option it doesn't need the opening tag, like:

php -r "echo 'ok';"


I hope this is not a duplicate, found nothing related when searching for the tag and word "PHP".

• Oct 2 '15 at 15:38
• In the linked Running PHP with -r instead of code tags, there is agreement that php -r is acceptable without code penalty. It follows that neither <? nor <?php are required. Oct 4 '15 at 3:47
As mentioned here, running programs via commands such as php -r "code here" is acceptable without penalty.
Since <? and <?php are both unneeded (and in fact not allowed) when using php -r, it follows that neither tags are required.
• But if I use <?= to save on echo that still counts as three bytes, because it cannot be done with php -r but has to be in a file, right? Aug 28 '16 at 13:37
• @YetiCGN Yes. We're effectively treating -r "code here" and filename here as separate languages. Dec 23 '17 at 16:46
Regarding the use of the <? short tag: since it's on by default, I think the use of <? instead of <?php is okay for code golf.