0

I understand this has been asked a bunch of times and probably appropriately answered so I ask you give me some grace here. I want to log errors to the error log but NOT display them to the client and for some reason nothing I've tried is making any difference. I'm currently using error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); and my PHP.ini has the following for display_errors:

display_errors = Off

I thought maybe the framework I'm using or some code was overwriting that value (possibly via ini_set()) but if I ask PHP what the value is via:

$display_errors = ini_get('display_errors');
if ( filter_var( $display_errors, FILTER_VALIDATE_BOOLEAN) ){
    echo "display_errors = true\n";
} else {
    echo "display_errors = false\n";
}

I get false (Note: I put the code at the end of the view/template for the framework). If I grep or use VSCode to search the codebase for display_errors I don't see any references that override the default behavior. If it makes any difference the actual value of display_errors as reported by ini_get() is an empty string ''. In case it's not clear this is in the context of Apache2 (Apache/2.4.29) on Ubuntu. What am I missing? Is there a third flag around displaying errors? TIA

Edited:
Framework is CodeIgniter v2.2.6 as reported by system/core/CodeIgniter.php.
PHP 7.2.24-0ubuntu0.18.04.13.
Apache2 (Apache/2.4.29)

5
  • You mention a framework, pleae tell us which one, it could be relevant Commented Oct 2, 2022 at 13:59
  • Create a quick script called check.php containing <?php phpinfo(); ?> and then run it in the browser. Look at the value for Loaded Configuration File on the first page, make sure you are amending the correct ``php.ini` file Commented Oct 2, 2022 at 14:11
  • I think this will answer you question : stackoverflow.com/questions/16184881/… Commented Oct 2, 2022 at 14:12
  • 1
    @RiggsFolly It reports /etc/php/7.2/apache2/php.ini which is what I'm editing. EDIT: Technically the setting there has always been display_errors = Off and error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT. Commented Oct 2, 2022 at 14:17
  • @AmanSingh My reading of that is I've already done the suggested steps. What are you thinking I'm missing? Commented Oct 2, 2022 at 14:18

1 Answer 1

1

I believe I found the answer for whatever other poor soul is still stuck on CodeIgniter v2. In system/core/Common.php there is a _exception_handler() function that has the following:

if (($severity & error_reporting()) == $severity)
{
    $_error->show_php_error($severity, $message, $filepath, $line);
}

The above appears to be what's causing errors to be shown to publicly and while could't find CI v2 code on Github I did see it was removed (or possibly just moved) in V3:

CodeIgniter V3 _exception_handler

Here is the complete (v2.2.6) function (unmodified in any way as far as I know):

// --------------------------------------------------------------------

/**
* Exception Handler
*
* This is the custom exception handler that is declaired at the top
* of Codeigniter.php.  The main reason we use this is to permit
* PHP errors to be logged in our own log files since the user may
* not have access to server logs. Since this function
* effectively intercepts PHP errors, however, we also need
* to display errors based on the current error_reporting level.
* We do that with the use of a PHP error template.
*
* @access   private
* @return   void
*/
if ( ! function_exists('_exception_handler'))
{
    function _exception_handler($severity, $message, $filepath, $line)
    {
         // We don't bother with "strict" notices since they tend to fill up
         // the log file with excess information that isn't normally very helpful.
        if ($severity == E_STRICT)
        {
            return;
        }

        $_error =& load_class('Exceptions', 'core');

        // Should we display the error? We'll get the current error_reporting
        // level and add its bits with the severity bits to find out.
        if (($severity & error_reporting()) == $severity)
        {
            $_error->show_php_error($severity, $message, $filepath, $line);
        }

        // Should we log the error?  No?  We're done...
        if (config_item('log_threshold') == 0)
        {
            return;
        }

        $_error->log_exception($severity, $message, $filepath, $line);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I had error notices on an old pyro site which just wouldn't go away no matter what! But this fixed it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.