Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Dec 25, 2025

before this change a call to match(1) would specify a expression $scope->expressionTypes[1] (integer key).
we expect this array to be keyed with string types though:

* @param array<string, ExpressionTypeHolder> $expressionTypes

In addition literal const scalar values do not make sense to be specified in scope.. it does not provide more information

found in snippet:

<?php declare(strict_types = 1); // lint >= 8.1

namespace Bug10418;

use function PHPStan\debugScope;

function (): void {
	$text = '123';
	$result = match(1){
		preg_match('/(\d+)/', $text, $match) => 'matched number: ' . $match[1],
		preg_match('/(\w+)/', $text, $match) => 'matched word: ' . json_encode($match),
		default => 'no matches!'
	};
	debugScope();
};

@ondrejmirtes
Copy link
Member

A similar skip could be done in TypeSpecifier::createForExpr as well.

@ondrejmirtes ondrejmirtes merged commit 9d8a923 into phpstan:2.1.x Dec 25, 2025
633 of 639 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@ondrejmirtes
Copy link
Member

The TypeSpecifier idea doesn't work, sometimes we have to report things like is_numeric('blabla') is always false.

@staabm staabm deleted the prevent branch December 25, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants