-1

I have a PHP REST API endpoint that throws an error:

PHP message: PHP Fatal error:  Uncaught Exception: Accessing static property...as non static in...

with the default error_reporting value but returns a correct value if error_reporting is set to 1, which I believe is E_ERROR.

Doesn't error_reporting just control the logging? This seems to control whether the exception is thrown as well, allowing the code to continue as normal.

I come from a Java background, used to using Logback and similar logging frameworks. In these frameworks, the log level refers to a filter for the recipient of the logs, commonly a log file. A log level X means that messages need to be at least level X (or lower than, I forget which) to be logged, but it doesn't affect whether the exception is thrown to begin with.

I had assumed that this was the case with PHP's error_reporting, however, based on the above behavior I am not sure.

I've looked through the PHP docs, but I haven't found a detailed explanationof how error_reporting works

So, my question: What does "reporting" mean here? Does error_reporting control more besides which exceptions/errors are logged?

xdhmoore
  • 8,935
  • 11
  • 47
  • 90

1 Answers1

1

error_reporting is a bit different with the log level, the argument is a set of toggles for each error type.

For example error_reporting(E_ERROR) only reports errors and error_reporting(E_NOTICE) only reports notices and error_reporting(E_ERROR|E_NOTICE) reports both errors and notices but doesn't report warnings.

FYI the error level of this message "Accessing static property...as non static in..." is E_STRICT in PHP 5 and E_NOTICE in PHP 7 by default.

This is weired because you got an exception, I guess the problem that changes the behaviour of the error is in your error handler.

shingo
  • 18,436
  • 5
  • 23
  • 42
  • Thanks, you were right, we had a custom error handler borrowed from [this answer](https://stackoverflow.com/a/47814000/356887). As my comment there says, it seems to change the default behavior of `error_reporting`. – xdhmoore Nov 18 '20 at 21:52