Make sure ContextErrorException is loaded during compile time errors

This commit is contained in:
ShiraNai7 2013-08-07 15:15:14 +02:00 committed by Fabien Potencier
parent ffe5567955
commit e47657dba1
2 changed files with 30 additions and 0 deletions

View File

@ -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);
}

View File

@ -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()
{