0

I'm debugging the PHP code of a big CMS, and I came across the fact that the following code

echo _NONEXISTING_CONSTANT_;

does not trigger any warning although the constant does not exist. Here is what I've tried to figure out why the warning is not displayed:

  • I've checked that error_reporting() & E_WARNING returns a non-zero value.
  • ob_get_level() returns 1.
  • If I put the same statement in the beginning of the first index.php, the error is displayed, so it's not a config setting.

What are possible mechanisms in PHP in which this code would not trigger a warning?

Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101
  • How is this related to xampp? – 0stone0 Apr 20 '21 at 13:19
  • 1
    An [error handler](https://www.php.net/manual/en/function.set-error-handler.php) perhaps? – Tim Apr 20 '21 at 13:20
  • Or, on php < 8, they could have disabled [warnings](https://stackoverflow.com/questions/16086589/how-to-overcome-php-notice-use-of-undefined-constant) – 0stone0 Apr 20 '21 at 13:22
  • I would also ask how you've determined that that constant doesn't exist. Did you `grep` for it or put an actual `defined` check? For the former, many CMSs allow plugins, extensions, drop-ins, etc. to define certain constants. – Chris Haas Apr 20 '21 at 13:46
  • Using `error_reporting()` without any parameters will return the current level. What does it return? – Tim Apr 20 '21 at 13:48
  • 1
    `display_errors` is of course also relevant, if you are expecting errors to appear in the output, and not just a log file. – CBroe Apr 20 '21 at 13:52
  • I looked but there is no error handler anywhere in the code (no explicit call to set_error_handler) – Mikaël Mayer Apr 23 '21 at 16:16
  • The constant does not exist because I wrote die(defined("_NONEXISTING_CONSTANT_") ? "Yes" : "no"); restarted the CMS and got a blank page with "no" on it. – Mikaël Mayer Apr 23 '21 at 16:18
  • error_reporting() returns E_ALL, meaning `error_reporting() & E_WARNING` returns a nonzero value, same as `error_reporting() & E_NOTICE`. – Mikaël Mayer Apr 23 '21 at 16:20
  • `display_errors` was the answer. It turns out it was set to "1" at the beginning and then "off" at the point the constant was evaluated. @CBroe can you create an answer, I'll accept it. – Mikaël Mayer Apr 23 '21 at 16:55

0 Answers0