Make sure ContextErrorException is loaded during compile time errors
This commit is contained in:
parent
ffe5567955
commit
e47657dba1
@ -120,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);
|
||||
}
|
||||
|
||||
|
@ -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