<?php
class ContextException extends RuntimeException {
protected $context = array();
public function __construct($message='', $context=array(), $code=0) {
$this->context = $context;
parent::__construct($message, $code);
}
/**
* Returns an array of variables that existed when exception occured.
* @return array Array of variable name=>value pairs.
*/
public function getContext(){
return $this->context;
}
}
$cheese = true;
throw new ContextException('Something went wrong.', get_defined_vars(), E_NOTICE);
Fatal error: Uncaught ContextException: Something went wrong. in /in/1rBWt:24
Stack trace:
#0 {main}
thrown in /in/1rBWt on line 24
Process exited with code 255.
Fatal error: Uncaught exception 'ContextException' with message 'Something went wrong.' in /in/1rBWt:24
Stack trace:
#0 {main}
thrown in /in/1rBWt on line 24
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Class 'RuntimeException' not found in /in/1rBWt on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/1rBWt on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/1rBWt on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/1rBWt on line 5
Process exited with code 255.