# PHP and warnings

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)

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

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

• 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 – Einacio Jun 2 '14 at 14:10
• Too lazy to search for it now, but I read that -n (no php.ini) comes free. – Titus Dec 21 '16 at 18:09
• @Titus I couldn't find it either, but this post likely predates it. I wouldn't say that -n is "free", but rather implicit. – primo Dec 22 '16 at 2:19

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.
• 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 – Einacio May 30 '14 at 16:38
• @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. – ProgramFOX May 30 '14 at 16:52
• 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 – Einacio May 30 '14 at 16:57
• @Einacio: I have removed that rule now and I leaved a comment. – ProgramFOX May 30 '14 at 16:58