mirror of
https://github.com/symfony/debug.git
synced 2026-03-25 09:42:20 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
085d4fd990 | ||
|
|
7f671456b9 | ||
|
|
234f31cd20 | ||
|
|
729f6d19cf | ||
|
|
947e8d434b |
@@ -58,7 +58,7 @@ class ErrorHandler
|
||||
* @param integer $level The level at which the conversion to Exception is done (null to use the error_reporting() value and 0 to disable)
|
||||
* @param Boolean $displayErrors Display errors (for dev environment) or just log they (production usage)
|
||||
*
|
||||
* @return The registered error handler
|
||||
* @return ErrorHandler The registered error handler
|
||||
*/
|
||||
public static function register($level = null, $displayErrors = true)
|
||||
{
|
||||
@@ -104,6 +104,7 @@ class ErrorHandler
|
||||
$stack = array_map(
|
||||
function ($row) {
|
||||
unset($row['args']);
|
||||
|
||||
return $row;
|
||||
},
|
||||
array_slice(debug_backtrace(false), 0, 10)
|
||||
@@ -119,6 +120,11 @@ class ErrorHandler
|
||||
}
|
||||
|
||||
if ($this->displayErrors && error_reporting() & $level && $this->level & $level) {
|
||||
// make sure the ContextErrorException class is loaded (https://bugs.php.net/bug.php?id=65322)
|
||||
if (!class_exists('Symfony\Component\Debug\Exception\ContextErrorException')) {
|
||||
require __DIR__.'/Exception/ContextErrorException.php';
|
||||
}
|
||||
|
||||
throw new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context);
|
||||
}
|
||||
|
||||
@@ -131,7 +137,7 @@ class ErrorHandler
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->reservedMemory);
|
||||
$this->reservedMemory = '';
|
||||
$type = $error['type'];
|
||||
if (0 === $this->level || !in_array($type, array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) {
|
||||
return;
|
||||
|
||||
@@ -19,18 +19,18 @@ namespace Symfony\Component\Debug\Exception;
|
||||
class ContextErrorException extends \ErrorException
|
||||
{
|
||||
private $context = array();
|
||||
|
||||
|
||||
public function __construct($message, $code, $severity, $filename, $lineno, $context = array())
|
||||
{
|
||||
parent::__construct($message, $code, $severity, $filename, $lineno);
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array Array of variables that existed when the exception occured
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
return $this->context;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,31 @@ use Symfony\Component\Debug\ErrorHandler;
|
||||
*/
|
||||
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCompileTimeError()
|
||||
{
|
||||
// the ContextErrorException must not be loaded for this test to work
|
||||
if (class_exists('Symfony\Component\Debug\Exception\ContextErrorException', false)) {
|
||||
$this->markTestSkipped('The ContextErrorException class is already loaded.');
|
||||
}
|
||||
|
||||
$handler = ErrorHandler::register(E_ALL | E_STRICT);
|
||||
$displayErrors = ini_get('display_errors');
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
try {
|
||||
// trigger compile time error
|
||||
eval(<<<'PHP'
|
||||
class _BaseCompileTimeError { function foo() {} }
|
||||
class _CompileTimeError extends _BaseCompileTimeError { function foo($invalid) {} }
|
||||
PHP
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
// if an exception is thrown, the test passed
|
||||
}
|
||||
|
||||
ini_set('display_errors', $displayErrors);
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user