diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/PdoStatementReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/PdoStatementReturnTypeProvider.php index 3edc2342bd1..03648afabd7 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/PdoStatementReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/PdoStatementReturnTypeProvider.php @@ -49,12 +49,16 @@ private static function handleFetch(MethodReturnTypeProviderEvent $event): ?Unio $source = $event->getSource(); $call_args = $event->getCallArgs(); $fetch_mode = 0; - - if (isset($call_args[0]) - && ($first_arg_type = $source->getNodeTypeProvider()->getType($call_args[0]->value)) - && $first_arg_type->isSingleIntLiteral() - ) { - $fetch_mode = $first_arg_type->getSingleIntLiteral()->value; + + foreach($call_args as $call_arg) { + $arg_name = $call_arg->name->name; + if (!isset($arg_name) || $arg_name === "mode") { + $first_arg_type = $source->getNodeTypeProvider()->getType($call_arg->value); + if ($first_arg_type->isSingleIntLiteral()) { + $fetch_mode = $first_arg_type->getSingleIntLiteral()->value; + } + break; + } } switch ($fetch_mode) {