Can I disable E_STRICT for library code, but not my code?

Is it possible to change the level of error messages (disable E_STRICT) for files that are included in my PHP application using includeor require_once?

I would like to see the strict notifications that occur in my code, but I use PEAR MDB2, and I get warning pages from this code when I turn on E_STRICT.

I know that it is possible to change error_reportingbased on each directory with the .htaccess file, but I do not think that this works with the included files. I tried to put it in the pear folder, but did nothing.

+3
source share
4 answers

$errfile, , . , . PHP.

, , .

backtrace, , , .

, :

<?php
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{

    $library_path = "/path/to/library";
    if (substr($errfile,0,strlen($library_path))==$library_path)
    /* Don't execute PHP internal error handler */
     return true;
    else
    /* execute PHP internal error handler */
     return false;
}
+5

error_reporting , ini_set(). :

// your running code using the default error reporting setting

// set the error reporting level for your library calls
ini_set('error_reporting', E_NOTICE);

// make some library calls

// reset the error reporting level back to strict
ini_set('error_reporting', E_ALL & E_STRICT);

// more of your code
+5

, .

ini_set('error_reporting', E_NOTICE);

/, .

0

, __call. , /:

class MyDb {
    protected $pearDb; // Instantiate this in your constructor.
    public function __call() {
        $oldReporting = error_reporting(~E_STRICT);
        $result = call_user_func_array(array($this->pearDb, __FUNCTION__), func_get_args());
        error_reporting($oldReporting);
        return $result;
    }
}

, , .

0

Source: https://habr.com/ru/post/1734080/


All Articles