Skip to content
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

ErrorHandler PHP 8.1 compatibility #10346

Merged
merged 3 commits into from Dec 9, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/composer
Expand Up @@ -10,6 +10,7 @@ require __DIR__.'/../src/bootstrap.php';

use Composer\Console\Application;
use Composer\XdebugHandler\XdebugHandler;
use Composer\Util\ErrorHandler;

error_reporting(-1);

Expand Down Expand Up @@ -57,6 +58,8 @@ if (function_exists('ini_set')) {

putenv('COMPOSER_BINARY='.realpath($_SERVER['argv'][0]));

ErrorHandler::register();

// run the command application
$application = new Application();
$application->run();
2 changes: 2 additions & 0 deletions src/Composer/Console/Application.php
Expand Up @@ -127,6 +127,8 @@ public function doRun(InputInterface $input, OutputInterface $output)
$io = $this->io = new ConsoleIO($input, $output, new HelperSet(array(
new QuestionHelper(),
)));

// Register error handler again to pass it the IO instance
ErrorHandler::register($io);

if ($input->hasParameterOption('--no-cache')) {
Expand Down
9 changes: 9 additions & 0 deletions src/Composer/Util/ErrorHandler.php
Expand Up @@ -52,6 +52,15 @@ public static function handle($level, $message, $file, $line)
}

if (self::$io) {
// ignore symfony/* deprecation warnings about return types
// also ignore them from the Composer namespace, as 1.x won't get all that fixed anymore
if (preg_match('{^Return type of (Symfony|Composer)\\\\.*ReturnTypeWillChange}is', $message)) {
return true;
}
if (strpos(strtr($file, '\\', '/'), 'vendor/symfony/') !== false) {
return true;
}

self::$io->writeError('<warning>Deprecation Notice: '.$message.' in '.$file.':'.$line.'</warning>');
if (self::$io->isVerbose()) {
self::$io->writeError('<warning>Stack trace:</warning>');
Expand Down