Page 1 of 1

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

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

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.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.




RSS Feed

Home Forums Web Development PHP – How to hide error notice for a specific line of code

This topic contains 0 replies, has 1 voice, and was last updated by  hans 3 weeks, 1 day ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • 12523

    hans
    Keymaster

    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.

Viewing 1 post (of 1 total)



You must be logged in to reply to this topic.