12
\$\begingroup\$

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".

\$\endgroup\$
3

2 Answers 2

10
\$\begingroup\$

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.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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? \$\endgroup\$
    – YetiCGN
    Commented Aug 28, 2016 at 13:37
  • 1
    \$\begingroup\$ @YetiCGN Yes. We're effectively treating -r "code here" and filename here as separate languages. \$\endgroup\$
    – wizzwizz4
    Commented Dec 23, 2017 at 16:46
7
\$\begingroup\$

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.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .