Skip to content

[PHP8.1][Console][Formatter] OutputFormatter.php - preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated #45544

Closed
@mrceperka

Description

@mrceperka

Symfony version(s) affected

symfony/console - 5.4.3

Description

When $message is null, this line breaks and throws warning.
https://github.com/symfony/console/blob/5.4/Formatter/OutputFormatter.php#L148

How to reproduce

<?php declare(strict_types = 1);

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class BrokenFormatterCommand extends Command
{
	protected static $defaultName = 'broken-formatter';

	/**
	 * @param InputInterface  $input
	 * @param OutputInterface $output
	 *
	 * @return int
	 */
	protected function execute(InputInterface $input, OutputInterface $output): int
	{
		$output->writeln('ok');
		
		// fails here
		$output->writeln(null);

		return 0;
	}
}

Possible Solution

Change affected line to:

preg_match_all("#<(($openTagRegex) | /($closeTagRegex)?)>#ix", $message ?? '', $matches, \PREG_OFFSET_CAPTURE);

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions