Skip to content

[Debug] simplify error_reporting levels given php version > 5.3 #16916

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
Dec 18, 2015
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
4 changes: 2 additions & 2 deletions src/Symfony/Component/Debug/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Debug
* @param int $errorReportingLevel The level of error reporting you want
* @param bool $displayErrors Whether to display errors (for development) or just log them (for production)
*/
public static function enable($errorReportingLevel = null, $displayErrors = true)
public static function enable($errorReportingLevel = E_ALL, $displayErrors = true)
{
if (static::$enabled) {
return;
Expand All @@ -42,7 +42,7 @@ public static function enable($errorReportingLevel = null, $displayErrors = true
if (null !== $errorReportingLevel) {
error_reporting($errorReportingLevel);
} else {
error_reporting(-1);
error_reporting(E_ALL);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a deprecation for the null case in 3.1 as it is useless now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might become an issue in the future when new constants are introduced in future PHP versions (similar to the introduction of the E_STRICT constant).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The E_ALL is supposed to include everything which is why it was changed in 5.4

}

if ('cli' !== php_sapi_name()) {
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/Debug/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ public static function register(self $handler = null, $replace = true)
register_shutdown_function(__CLASS__.'::handleFatalError');
}

$levels = -1;

if ($handlerIsNew = null === $handler) {
$handler = new static();
}
Expand All @@ -131,7 +129,7 @@ public static function register(self $handler = null, $replace = true)
restore_error_handler();
}

$handler->throwAt($levels & $handler->thrownErrors, true);
$handler->throwAt(E_ALL & $handler->thrownErrors, true);

return $handler;
}
Expand All @@ -151,7 +149,7 @@ public function __construct(BufferingLogger $bootstrappingLogger = null)
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
* @param bool $replace Whether to replace or not any existing logger
*/
public function setDefaultLogger(LoggerInterface $logger, $levels = null, $replace = false)
public function setDefaultLogger(LoggerInterface $logger, $levels = E_ALL, $replace = false)
{
$loggers = array();

Expand All @@ -163,7 +161,7 @@ public function setDefaultLogger(LoggerInterface $logger, $levels = null, $repla
}
} else {
if (null === $levels) {
$levels = E_ALL | E_STRICT;
$levels = E_ALL;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a deprecation for the null case in 3.1 as it is useless now.

}
foreach ($this->loggers as $type => $log) {
if (($type & $levels) && (empty($log[0]) || $replace || $log[0] === $this->bootstrappingLogger)) {
Expand Down Expand Up @@ -255,7 +253,7 @@ public function setExceptionHandler(callable $handler = null)
public function throwAt($levels, $replace = false)
{
$prev = $this->thrownErrors;
$this->thrownErrors = (E_ALL | E_STRICT) & ($levels | E_RECOVERABLE_ERROR | E_USER_ERROR) & ~E_USER_DEPRECATED & ~E_DEPRECATED;
$this->thrownErrors = E_ALL & ($levels | E_RECOVERABLE_ERROR | E_USER_ERROR) & ~E_USER_DEPRECATED & ~E_DEPRECATED;
if (!$replace) {
$this->thrownErrors |= $prev;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->errorReporting = error_reporting(E_ALL | E_STRICT);
$this->errorReporting = error_reporting(E_ALL);
$this->loader = new ClassLoader();
spl_autoload_register(array($this->loader, 'loadClass'), true, true);
DebugClassLoader::enable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class DebugHandlersListener implements EventSubscriberInterface
* @param bool $scream Enables/disables screaming mode, where even silenced errors are logged
* @param string $fileLinkFormat The format for links to source files
*/
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = null, $throwAt = -1, $scream = true, $fileLinkFormat = null)
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = E_ALL, $throwAt = E_ALL, $scream = true, $fileLinkFormat = null)
{
$this->exceptionHandler = $exceptionHandler;
$this->logger = $logger;
$this->levels = $levels;
$this->throwAt = is_numeric($throwAt) ? (int) $throwAt : (null === $throwAt ? null : ($throwAt ? -1 : null));
$this->levels = null === $levels ? E_ALL : $levels;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a deprecation for the null case in 3.1 as it is useless now.

$this->throwAt = is_numeric($throwAt) ? (int) $throwAt : (null === $throwAt ? null : ($throwAt ? E_ALL : null));
$this->scream = (bool) $scream;
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public function configure(Event $event = null)
$scream |= $type;
}
} else {
$scream = null === $this->levels ? E_ALL | E_STRICT : $this->levels;
$scream = $this->levels;
}
if ($this->scream) {
$handler->screamAt($scream);
Expand Down