<?php
class CErrorException extends Exception {}
function handleError($level, $message, $file, $line){
var_dump(error_reporting());
if( error_reporting() != 0){
throw new CErrorException($message, $level);
}
}
function handleException(Exception $exception){
var_dump('Exception handled at global level');
}
set_error_handler('handleError');
set_exception_handler('handleException');
try {
require_once('non\existent\file'); //Will generate an error and cause an exception to be thrown.
} catch (Exception $e) {
var_dump("let's deal with the exception");
}
int(-1)
string(29) "let's deal with the exception"
Output for 8.0.13
int(32767)
string(29) "let's deal with the exception"
Output for 8.0.0 - 8.0.2
int(-1)
Fatal error: Uncaught TypeError: handleException(): Argument #1 ($exception) must be of type Exception, Error given in /in/ljehL:11
Stack trace:
#0 [internal function]: handleException(Object(Error))
#1 {main}
thrown in /in/ljehL on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.7, 7.4.33
int(-1)
Warning: Uncaught CErrorException: require_once(non\existent\file): failed to open stream: No such file or directory in /in/ljehL:7
Stack trace:
#0 /in/ljehL(20): handleError(2, 'require_once(no...', '/in/ljehL', 20, Array)
#1 /in/ljehL(20): require_once()
#2 {main}
thrown in /in/ljehL on line 7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/ljehL on line 20
Process exited with code 255.
int(-1)
Warning: Uncaught CErrorException: require_once(): open_basedir restriction in effect. File(non\existent\file) is not within the allowed path(s): (/tmp:/in:/etc) in /in/ljehL:7
Stack trace:
#0 /in/ljehL(20): handleError(2, 'require_once():...', '/in/ljehL', 20, Array)
#1 /in/ljehL(20): require_once()
#2 {main}
thrown in /in/ljehL on line 7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/ljehL on line 20
Process exited with code 255.
Output for 7.3.32 - 7.3.33
int(22519)
Warning: Uncaught CErrorException: require_once(non\existent\file): failed to open stream: No such file or directory in /in/ljehL:7
Stack trace:
#0 /in/ljehL(20): handleError(2, 'require_once(no...', '/in/ljehL', 20, Array)
#1 /in/ljehL(20): require_once()
#2 {main}
thrown in /in/ljehL on line 7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/ljehL on line 20
Process exited with code 255.
Output for 7.1.20, 7.2.6
int(-1)
Warning: Uncaught CErrorException: require_once(): open_basedir restriction in effect. File(non\existent\file) is not within the allowed path(s): (/tmp:/in) in /in/ljehL:7
Stack trace:
#0 /in/ljehL(20): handleError(2, 'require_once():...', '/in/ljehL', 20, Array)
#1 /in/ljehL(20): require_once()
#2 {main}
thrown in /in/ljehL on line 7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/ljehL on line 20
Process exited with code 255.
int(-1)
Warning: Uncaught exception 'CErrorException' with message 'require_once(non\existent\file): failed to open stream: No such file or directory' in /in/ljehL:7
Stack trace:
#0 /in/ljehL(20): handleError(2, 'require_once(no...', '/in/ljehL', 20, Array)
#1 /in/ljehL(20): require_once()
#2 {main}
thrown in /in/ljehL on line 7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/ljehL on line 20
Process exited with code 255.
Output for 5.3.3 - 5.3.17, 5.4.0 - 5.4.7
int(-1)
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/ljehL on line 20
Process exited with code 255.
Output for 5.3.0 - 5.3.2
int(-1)
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/ljehL on line 0
Process exited with code 255.