bug #17347 [2.7] Workaround https://bugs.php.net/63206 (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[2.7] Workaround https://bugs.php.net/63206

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

d44e0b7 [2.7] Workaround https://bugs.php.net/63206
This commit is contained in:
Nicolas Grekas 2016-01-13 10:06:51 +01:00
commit fe83ab953e
4 changed files with 21 additions and 13 deletions

View File

@ -95,6 +95,7 @@ class ErrorHandler
private $loggedTraces = array();
private $isRecursive = 0;
private $isRoot = false;
private $exceptionHandler;
private static $reservedMemory;
@ -134,7 +135,12 @@ class ErrorHandler
$handler = new static();
}
$prev = set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
if (null === $prev = set_error_handler(array($handler, 'handleError'))) {
restore_error_handler();
// Specifying the error types earlier would expose us to https://bugs.php.net/63206
set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
$handler->isRoot = true;
}
if ($handlerIsNew && is_array($prev) && $prev[0] instanceof self) {
$handler = $prev[0];
@ -326,12 +332,16 @@ class ErrorHandler
private function reRegister($prev)
{
if ($prev !== $this->thrownErrors | $this->loggedErrors) {
$handler = set_error_handler('var_dump', 0);
$handler = set_error_handler('var_dump');
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
if ($handler === $this) {
restore_error_handler();
set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors);
if ($this->isRoot) {
set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors);
} else {
set_error_handler(array($this, 'handleError'));
}
}
}
}
@ -527,7 +537,7 @@ class ErrorHandler
self::$reservedMemory = null;
$handler = set_error_handler('var_dump', 0);
$handler = set_error_handler('var_dump');
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
@ -672,7 +682,7 @@ class ErrorHandler
{
@trigger_error('The '.__METHOD__.' static method is deprecated since version 2.6 and will be removed in 3.0. Use the setLoggers() or setDefaultLogger() methods instead.', E_USER_DEPRECATED);
$handler = set_error_handler('var_dump', 0);
$handler = set_error_handler('var_dump');
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
if (!$handler instanceof self) {

View File

@ -175,7 +175,7 @@ class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase
*/
public function testDeprecatedSuper($class, $super, $type)
{
set_error_handler('var_dump', 0);
set_error_handler(function() { return false; });
$e = error_reporting(0);
trigger_error('', E_USER_DEPRECATED);
@ -205,7 +205,7 @@ class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase
public function testDeprecatedSuperInSameNamespace()
{
set_error_handler('var_dump', 0);
set_error_handler(function() { return false; });
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);
@ -231,7 +231,7 @@ class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('PHP7 already prevents using reserved names.');
}
set_error_handler('var_dump', 0);
set_error_handler(function() { return false; });
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);

View File

@ -68,9 +68,8 @@ class LockHandler
return true;
}
// Silence both userland and native PHP error handlers
$errorLevel = error_reporting(0);
set_error_handler('var_dump', 0);
// Silence error reporting
set_error_handler(function() {});
if (!$this->handle = fopen($this->file, 'r')) {
if ($this->handle = fopen($this->file, 'x')) {
@ -81,7 +80,6 @@ class LockHandler
}
}
restore_error_handler();
error_reporting($errorLevel);
if (!$this->handle) {
$error = error_get_last();

View File

@ -67,7 +67,7 @@ class DebugHandlersListener implements EventSubscriberInterface
}
$this->firstCall = false;
if ($this->logger || null !== $this->throwAt) {
$handler = set_error_handler('var_dump', 0);
$handler = set_error_handler('var_dump');
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
if ($handler instanceof ErrorHandler) {