12
\$\begingroup\$

Sometimes when golfing in PHP, one uses tricks as reading/pushing to an inexistent variable, or using deprecated functions such as split(), but those things outputs Warnings and Notices, which by themselves are not really errors and don't change how the code works.

Is there any policy regarding the output of these type of errors?

Should I add provisions to remove or hide the warnings in my code even if the questions doesn't ask it as a requirement or should I consider that the PHP configuration has error_reporting = 0?

I have seen C answers that output compiler warnings (the closest equivalent I can think now)

\$\endgroup\$
  • \$\begingroup\$ I think you can say "This submission will generate PHP warnings that can be suppressed by using php ./program.php 2>/dev/null"? \$\endgroup\$ – user12205 May 30 '14 at 16:32
  • \$\begingroup\$ @ace wouldn't that also suppress the program's normal output? \$\endgroup\$ – Einacio May 30 '14 at 16:37
  • 2
    \$\begingroup\$ Only if your "normal" output is to stderr. \$\endgroup\$ – user12205 May 30 '14 at 16:42
  • \$\begingroup\$ @ace by default php sends errors to stdout, unless the ini directive display_errors is set to 'stderr' \$\endgroup\$ – Einacio May 30 '14 at 16:50
  • 13
    \$\begingroup\$ I'd even go so far as to say that abusing warnings is encouraged, in the spirit of code golf. ;-) \$\endgroup\$ – Doorknob May 30 '14 at 17:02
14
\$\begingroup\$

Assume Default Settings

I have been informed with some frequency that my PHP solutions "don't work", typically due to an abundance of E_NOTICE messages. I suggest the following settings be assumed by default:

short_open_tag = On
precision = 14
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

These are all default values, as they would be without a configuration file. For example, the following should be valid, even in challenges where producing any errors is prohibited:

<?for(;$i++<10;);

despite generating an E_NOTICE, due to accessing a previously undefined variable. This message is by default not displayed. On a similar note, suppressing errors with @ should also be allowed in these cases.

\$\endgroup\$
  • 1
    \$\begingroup\$ i know it's not competitive, that's why i try to use it anyways. i don't have to imagine the mysql error in the wild, i have seen it too often already \$\endgroup\$ – Einacio Jun 2 '14 at 14:10
  • \$\begingroup\$ Too lazy to search for it now, but I read that -n (no php.ini) comes free. \$\endgroup\$ – Titus Dec 21 '16 at 18:09
  • \$\begingroup\$ @Titus I couldn't find it either, but this post likely predates it. I wouldn't say that -n is "free", but rather implicit. \$\endgroup\$ – primo Dec 22 '16 at 2:19
11
\$\begingroup\$

There currently is no policy about that, but this is my opinion:

  • Does the question explicitly disallow code that can lead to a Warning/Notice? Then it is disallowed.
  • Does the question say nothing about such code? Then it would say it is allowed (and you can assume that error_reporting = 0), because none of the rules say that it is disallowed.
\$\endgroup\$
  • \$\begingroup\$ the question has been in my mind for a while, but i posted now after this question:codegolf.stackexchange.com/questions/28801/missing-odd-numbers in which that rule was added after i posted my solution \$\endgroup\$ – Einacio May 30 '14 at 16:38
  • \$\begingroup\$ @Einacio: A rule update after an answer is posted is discouraged, because it can invalidate answers, and it invalidated yours. I'll remove that rule. \$\endgroup\$ – ProgramFOX May 30 '14 at 16:52
  • \$\begingroup\$ actually, i had to add 1 character to avoid a warning. the decrease was beacuse a reorganization of code (which didn't output errors). anyways, this question is to see if we can have some official policy regarding this, i don't care about the specifics of that answer \$\endgroup\$ – Einacio May 30 '14 at 16:57
  • \$\begingroup\$ @Einacio: I have removed that rule now and I leaved a comment. \$\endgroup\$ – ProgramFOX May 30 '14 at 16:58

You must log in to answer this question.

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