Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Closed
mrceperka opened this issue Feb 24, 2022 · 1 comment

Comments

@mrceperka
Copy link

mrceperka commented Feb 24, 2022

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

@derrabus
Copy link
Member

#45546

@fabpot fabpot closed this as completed Feb 25, 2022
fabpot added a commit that referenced this issue Feb 25, 2022
This PR was merged into the 5.4 branch.

Discussion
----------

[Console] Fix null handling in formatAndWrap()

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45544
| License       | MIT
| Doc PR        | N/A

Commits
-------

74719e7 [Console] Fix null handling in formatAndWrap()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants