Page 1 of 1

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!

Clear all

PHP - How to hide error notice for a specific line of code  


Noble Member Admin
Joined: 7 years ago
Posts: 1298
September 29, 2019 4:08 AM  

Not something you'd want to use every day, but sometimes you want to make sure that one specific line doesn't produce a "Notice" error in PHP. Well, it's not really an error, but anyhoo, you'd want to hide that line.

I had this while checking for bbPress being active or not:

$bbPress_Found = function_exists(is_bbpress); // either TRUE or FALSE

Which produces the notice message:

Notice: Use of undefined constant is_bbpress - assumed 'is_bbpress' in /path/to/offendingfile.php on line 26

To "hide" the message for just this single line, change the error level before and after the call;

$errorLevel = error_reporting(E_ALL & ~E_NOTICE);    // disable E_NOTICE errors
$bbPress_Found = function_exists(is_bbpress); // offending line ...
error_reporting($errorLevel); // restore error level

Now in debug mode, it will not produce an "notice" for this specific line.