Question

Shorter explanation:

I've realised I posted this as a really long-winded explanation - I've left the previous explanation below but added a shorter summary.

In my CodeIgniter application, the error reporting level is set to 0. If I try to reference an undefined index (for example) in a controller or view, no error is outputted which is as expected.

However, I have a library, which loads in a third party class (NuSoap).

If the NuSoap class experiences an error - it will still output the error in my application.

Errors will also be outputted if the error is encountered in the library file itself.

Why is this? If it's being loaded in through CodeIgniter, through a library surely it should inherit the error reporting level?


Previous (long-winded) explanation:

I'm having some trouble understanding how the error reporting is working throughout my CodeIgniter application.

In index.php my error reporting is set up as follows:

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
        break;

        case 'testing':
        case 'production':
            error_reporting(0);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
}

I'm using the production environment, so my expected output when an error/warning/notice is due would be that nothing is displayed, but this isn't the case.

It's taken a while to get this far but I've made a couple of discoveries.

The reason I've picked up on this is during testing. My aim was to catch any errors connecting to an API we use which we connect to using a NuSoap client.

When I changed the username/password to make them deliberately incorrect, I found that PHP notices were being outputted from the NuSoap class - however my error reporting level is set to 0.

The error is a PHP Notice (Undefined index)

I have a library which included the main NuSoap class:

<?php

if(!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class NuSoap {

    var $nusoap_client;

    public function __construct() {
        /* Load the NuSoap class */
        require_once('../httpdocs/application/libraries/nusoap/nusoap.php');
        /* Initialise the NuSoap client */
        $this->nusoap_client = new nusoap_client(NUSOAP_WSDL_FILE, 'wsdl', '', '', '', '', 120, 120);
        /* Set the credentials */
        $this->nusoap_client->set_credentials(USERNAME, PASSWORD);
        $this->nusoap_client = $this->nusoap_client->getProxy();
    }

}

?>

And the error is coming from the included file /application/libraries/nusoap/nusoap.php

In a seperate controller, which doesn't use the NuSoap library, I placed the following code in the index function:

$arr = array(); $arr['exists'] = true;
echo 'deliberate error - ' . $arr['not_exists'];
die(phpinfo());

Now going on the fact that the NuSoap class is outputting a notice for an undefined error, I would also expect the above to, but it doesn't.

Also - in the PHP Info output the following doesn't make sense to me:

Directive       Local Value Master Value
display_errors  On          On

If display_errors is on - why are they not being outputted here?

To suppress the errors being generated in nusoap.php, I've found that putting error_reporting(0) at the top of the file will do this. What I can't understand is why the error reporting configuration in CodeIgniter isn't affecting this file even though it is loaded in by a CodeIgniter library?

Was it helpful?

Solution

It seems that it was only happening in a library when another library was loaded before the library in question.

The library causing the issue was PHPGrid, which was setting display_errors to 1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top