• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to prevent CI from reporting PHP Notice errors

#1
I don't have much experience with CI, but I have inherited a project that uses it.

As the title says, how do you prevent CI from reporting PHP notice errors?

In the index.php file there's the following;

PHP Code:
switch (ENVIRONMENT) {
 
   case 'development':
 
       ini_set('display_errors'1);
 
       ini_set('display_startup_errors'1);
 
       error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
 
       break;
 
   case 'testing':
 
   case 'production':
 
       ini_set('display_errors'0);
 
       if (version_compare(PHP_VERSION'5.3''>=')) {
 
           error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
 
       } else {
 
           error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
 
       }
 
       break;
 
   default:
 
       header('HTTP/1.1 503 Service Unavailable.'TRUE503);
 
       echo 'The application environment is not set correctly.';
 
       exit(1); // EXIT_ERROR
}

I have checked that the environment is set to productionso PHP shouldn't be reporting notice errors, but for some reason CI is still displaying them? 
Reply

#2
@shepparddigital,

What version of CI is it?

If it is 3.x then here is the documentation: https://codeigniter.com/user_guide/gener...r-handling
- in your switch case for 'production' add this statement: error_reporting(0);
Reply

#3
Yes, it's 3.x, I've followed the documentation, and you can clearly see that on the 'development' environment I've changed the log level via error_reporting() to display all errors except notices, strict errors and user notices, but for one reason or another CI is still outputting those errors.

In the file application/config.php I have also set $config['log_threshold'] = 1;

Why is CI still outputting notices? What am I missing?
Reply

#4
(07-04-2019, 03:06 AM)shepparddigital Wrote: Yes, it's 3.x, I've followed the documentation, and you can clearly see that on the 'development' environment I've changed the log level via error_reporting() to display all errors except notices, strict errors and user notices, but for one reason or another CI is still outputting those errors.

In the file application/config.php I have also set $config['log_threshold'] = 1;

Why is CI still outputting notices? What am I missing?

Very strange!
I tested on my server and it works...
1. perhaps'a you may have an overlaod controller for Exceptions (search under application/core)
2. maybe you have a try-catch-finally block on your own controller
3. be sure the CI code is clean: you must have in line 612 (system/core/Common.php):

PHP Code:
if (($severity error_reporting()) !== $severity)
        {
            return;
        } 

can you post the controller source code that has this problem
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
3 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.