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

Wrong assumption on array merge #5169

Closed
dereuromark opened this issue Jun 13, 2021 · 5 comments
Closed

Wrong assumption on array merge #5169

dereuromark opened this issue Jun 13, 2021 · 5 comments

Comments

@dereuromark
Copy link
Contributor

dereuromark commented Jun 13, 2021

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/86239cd8-0802-4070-8bdf-b773187103ee

	/**
	 * @param array $configs
	 *
	 * @return array
	 */	
	protected function merge(array $configs): array {
		$result = [];
		foreach ($configs as $config) {
			$result += $config;

			foreach ($config as $name => $dto) {
				$result[$name] += $dto;
			}
		}

		return $result;
	}

Expected output

no issue as long as we do not document this any further, just as before.
This didn't error a few patches before. So this looks like a too strict regression of sorts.

@ondrejmirtes
Copy link
Member

PHPStan's error is expected, see: https://3v4l.org/QipVB

You need more specific PHPDocs telling what's in $configs.

@ondrejmirtes
Copy link
Member

I realized what actually changed it, just a moment.

@ondrejmirtes
Copy link
Member

But it doesn't change you should actually fix your code :) But I'll make PHPStan stop reporting this.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@2abb92e

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants