Skip to content

*ParameterClosureTypeExtension for functions which accept a array of callables #11438

@staabm

Description

@staabm

Feature request

using *ParameterClosureTypeExtension for preg_replace_callback in phpstan/phpstan-src#3281 worked like a charm. I was able to easily wire togehter the RegexArrayShapeMatcher with the closure arg.

I try to do a similar thing for preg_replace_callback_array but since this function has a array-of-callables as a first arg my *ParameterClosureTypeExtension is not invoked.

example code

preg_replace_callback_array(
	[
		'~A([a]+)~i' => function ($match) {
		var_dump($match);
			\PHPStan\Testing\assertType('list<string>', $match);
		},
		'~B([b]+)?~i' => function ($match) {
			//var_dump($match);
		},
		'/(foo)?(bar)?(baz)?/' => function ($match) {
			//var_dump($match);
		},
	],
	$subject
);

I think we either need a way to handle array-of-callables, or we need to hardcode preg_replace_callback_array directly into NodeScopeResolver - or maybe there is another path I did not yet think of.

lets use this issue to figure out how this can/should be done :-)

Did PHPStan help you today? Did it make you happy in any way?

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