<?php
class CErrorException extends Exception {}
function handleError($level, $message, $file, $line){
if( error_reporting() != 0){
throw new CErrorException($message, $level);
}
}
function handleException($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");
}
Warning: Uncaught CErrorException: require_once(non\existent\file): failed to open stream: No such file or directory in /in/sKc4X:7
Stack trace:
#0 /in/sKc4X(20): handleError(2, 'require_once(no...', '/in/sKc4X', 20, Array)
#1 /in/sKc4X(20): require_once()
#2 {main}
thrown in /in/sKc4X on line 7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/sKc4X on line 20
Process exited with code 255.
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/sKc4X:7
Stack trace:
#0 /in/sKc4X(20): handleError(2, 'require_once():...', '/in/sKc4X', 20, Array)
#1 /in/sKc4X(20): require_once()
#2 {main}
thrown in /in/sKc4X on line 7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/sKc4X on line 20
Process exited with code 255.
Output for 7.1.20
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/sKc4X:7
Stack trace:
#0 /in/sKc4X(20): handleError(2, 'require_once():...', '/in/sKc4X', 20, Array)
#1 /in/sKc4X(20): require_once()
#2 {main}
thrown in /in/sKc4X on line 7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/sKc4X on line 20
Process exited with code 255.
Warning: Uncaught exception 'CErrorException' with message 'require_once(non\existent\file): failed to open stream: No such file or directory' in /in/sKc4X:7
Stack trace:
#0 /in/sKc4X(20): handleError(2, 'require_once(no...', '/in/sKc4X', 20, Array)
#1 /in/sKc4X(20): require_once()
#2 {main}
thrown in /in/sKc4X on line 7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/sKc4X on line 20
Process exited with code 255.
Output for 5.3.3 - 5.3.17, 5.4.0 - 5.4.7
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/sKc4X on line 20
Process exited with code 255.
Output for 5.3.0 - 5.3.2
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/sKc4X on line 0
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Fatal error: main(): Failed opening required 'non\existent\file' (include_path='.:') in /in/sKc4X on line 23
Process exited with code 255.
<br />
<b>Fatal error</b>: main() [<a href='function.require'>function.require</a>]: Failed opening required 'non\existent\file' (include_path='.:') in <b>/in/sKc4X</b> on line <b>23</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br />
<b>Parse error</b>: syntax error, unexpected T_NEW in <b>/in/sKc4X</b> on line <b>7</b><br />
Process exited with code 255.