1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Warn about array_walk_recursive over objects

This commit is contained in:
Bruce Weirdan 2021-08-31 23:18:20 +03:00
parent b370ce92aa
commit 103b2b7244
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 12 additions and 1 deletions

View File

@ -404,7 +404,11 @@ class NamedFunctionCallHandler
}
}
if ($first_arg && $function_id === 'array_walk') {
if ($first_arg
&& ($function_id === 'array_walk'
|| $function_id === 'array_walk_recursive'
)
) {
$first_arg_type = $statements_analyzer->node_data->getType($first_arg->value);
if ($first_arg_type && $first_arg_type->hasObjectType()) {

View File

@ -2177,6 +2177,13 @@ class ArrayFunctionCallTest extends TestCase
',
'error_message' => 'RawObjectIteration',
],
'arrayWalkRecursiveOverObject' => [
'<?php
$o = new stdClass();
array_walk_recursive($o, "var_dump");
',
'error_message' => 'RawObjectIteration',
],
];
}
}