`*ParameterClosureTypeExtension` for functions which accept a array of callables
Author: staabmCreated Aug 2, 2024Updated Sep 14, 2026
Labelsfeature-request
Feature request
using *ParameterClosureTypeExtension for preg_replace_callback in https://github.com/phpstan/phpstan-src/pull/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
Source: phpstan/phpstan