Page 1 of 1
Forum

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 no translation for that post!



PHP - How to hide e...
 
Share:
Notifications
Clear all

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

1 Posts
1 Users
0 Likes
1,312 Views
 Hans
(@hans)
Noble Member Admin
Joined: 11 years ago
Posts: 1065
Topic starter  

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.


   
ReplyQuote
Share: