SOURCE

errors.php

Transforms any runtime error into exception and adds safety and security checks. By requiring this package, error handling of a program radically changes whenever an error occurs. Hopefully, all this shall make the program safer and simpler.

Check proper php.ini be loaded
A run-time check is performed on the actual php.ini configuration file in use. A fatal error is triggered if either the wrong configuration file was read or no configuration file has been read at all. Different php.ini files can be set depending on the current SAPI the interpreter is running under. By default, the php.ini used for the CLI and CGI SAPI is those provided by PHPLint under this same directory. If the web server PHP module is used instead, the specific path of the php.ini file MUST be set by hand in the code of this module, see the phplint_check_php_ini() function.

Maximum error level
All the possible errors that the PHP engine or the application may trigger are enabled, so that even the smallest notice which normally PHP programmers ignore is now thrown as exception.

Errors become ErrorException
Second, every function and method, be it PHP built-in or defined by the user, that may trigger an error (here including E_NOTICE) now may throw ErrorException. PHPLint is made aware of these important changes. This is the case, for example, of functions like fopen() and all the I/O functions, unserialize(), hex2bin(), parse_url(), array_chunk(), array_fill(), and many others which now may fail throwing this exception. Note that ErrorException is checked, so you have the choice to either capture it with try/catch, or declare it as thrown by your function or method using the @throws line tag, but you cannot ignore it. The error silencer operator @ cannot be used anymore, as errors must now be handled as exceptions. The usual code:

$f = @fopen("afile.txt", "r");
if( $f === FALSE )
    die($(string) error_get_last()['message']);
now becomes:
try {
    $f = fopen("afile.txt", "r");
} catch(ErrorException $e){
    die($e->getMessage());
}

Core errors become unchecked InternalException
The last important difference is that errors triggered by the PHP engine are now translated to the unchecked InternalException exception. Being unchecked, you should not try to handle it as it normally indicates a bug internal to the program the program itself cannot address (and should not generate, in the first place). A partial list of the engine errors that throw InternalException follows:

Several other errors the engine may generate cannot happen once the source had been validated with PHPLint: missing mandatory arguments in function or method call; accessing an array using a key that cannot be converted to int or string; using the value of an undefined variable; implicit conversion to string of an object that does not implement __toString(); implicit conversion to string of array; defining a constant already defined.

Fatal errors are still... fatal
Many other errors are fatal and cannot be handled by the program at all: $a=NULL; $a->m();, require() and require_once() failure; memory exausted; invalid type for the argument of a function as in ord(array()), ...

The silencer operator @ cannot be used anymore
The usual programming style (that is, performing error detection using the error silencer operator and checking the returned value) cannot be mixed with this new behavior anymore. Most of the PHPLint Standard Library includes this file. PHPLint warns with an error if this package gets included after a possible error condition has been detected before in the code.

Uncaught exceptions are reported on standard error
Uncaught exceptions are reported on standard error along with the call stack trace, and the program terminates with exit code of 1.
Author: Umberto Salsi <salsi@icosaedro.it>
Version: $Date: 2020/03/08 10:31:23 $

Functions


logCapturedException()

void logCapturedException(Exception $e)

Logs to standard error a captured exception, including stack trace and previous exception (this latter displayed first).

Classes


InvalidConfiguration

unchecked class InvalidConfiguration
      |  
      `--Exception
           `--Throwable

{

Inherited properties: $code, $file, $line, $message
Inherited methods: __clone(), __construct(), __toString(), getCode(), getFile(), getLine(), getMessage(), getPrevious(), getTrace(), getTraceAsString()
}

Private items

Private functions: phplint_check_php_ini(), phplint_error_handler(), phplint_error_level(), phplint_exception_handler()

Requirements

PHP Version: 7

Required modules: core, file, phpinfo

Required packages: InternalException.php


Generated by PHPLint Documentator