8000 [2.7] Workaround https://bugs.php.net/63206 by nicolas-grekas · Pull Request #17347 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[2.7] Workaround https://bugs.php.net/63206
  • Loading branch information
nicolas-grekas committed Jan 13, 2016
commit d44e0b7212f98f38d7876620ce08c5ccbde39e7c
20 changes: 15 additions & 5 deletions src/Symfony/Component/Debug/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ErrorHandler

private $loggedTraces = array();
private $isRecursive = 0;
private $isRoot = false;
private $exceptionHandler;

private static $reservedMemory;
Expand Down Expand Up @@ -134,7 +135,12 @@ public static function register($handler = null, $replace = true)
$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];
Expand Down Expand Up @@ -326,12 +332,16 @@ public function screamAt($levels, $replace = false)
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'));
}
}
}
}
Expand Down Expand Up @@ -527,7 +537,7 @@ public static function handleFatalError(array $error = null)

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();

Expand Down Expand Up @@ -672,7 +682,7 @@ public static function setLogger(LoggerInterface $logger, $channel = 'deprecatio
{
@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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function testClassAlias()
*/
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);

Expand Down Expand Up @@ -205,7 +205,7 @@ public function provideDeprecatedSuper()

public function testDeprecatedSuperInSameNamespace()
{
set_error_handler('var_dump', 0);
set_error_handler(function() { return false; });
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);

Expand All @@ -231,7 +231,7 @@ public function testReservedForPhp7()
$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);

Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/Filesystem/LockHandler.php
D67E
Original file line numberDiff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ public function lock($blocking = false)
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')) {
Expand All @@ -81,7 +80,6 @@ public function lock($blocking = false)
}
}
restore_error_handler();
error_reporting($errorLevel);

if (!$this->handle) {
$error = error_get_last();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function configure(Event $event = null)
}
$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) {
Expand Down
0