diff --git a/src/Psalm/Internal/Codebase/Functions.php b/src/Psalm/Internal/Codebase/Functions.php index 1861e3239..c88fb2988 100644 --- a/src/Psalm/Internal/Codebase/Functions.php +++ b/src/Psalm/Internal/Codebase/Functions.php @@ -346,6 +346,11 @@ class Functions return false; } + // $matches is basically the (conditional) output of these functions + if ($function_id === 'preg_match' || $function_id === 'preg_match_all') { + return true; + } + $function_callable = \Psalm\Internal\Codebase\CallMap::getCallableFromCallMapById( $codebase, $function_id, @@ -356,12 +361,6 @@ class Functions return false; } - foreach ($function_callable->params as $i => $param) { - if ($param->by_ref && isset($args[$i])) { - return false; - } - } - return true; } diff --git a/src/Psalm/Internal/Stubs/CoreGenericFunctions.php b/src/Psalm/Internal/Stubs/CoreGenericFunctions.php index a35daa9e6..81072aa79 100644 --- a/src/Psalm/Internal/Stubs/CoreGenericFunctions.php +++ b/src/Psalm/Internal/Stubs/CoreGenericFunctions.php @@ -7,6 +7,7 @@ * @param bool $strict * * @return array + * @psalm-pure */ function array_keys(array $arr, $search_value = null, bool $strict = false) { @@ -18,6 +19,7 @@ function array_keys(array $arr, $search_value = null, bool $strict = false) * @param array $arr * * @return array + * @psalm-pure */ function array_values(array $arr) { @@ -31,6 +33,7 @@ function array_values(array $arr) * @param int $sort_flags * * @return array + * @psalm-pure */ function array_unique(array $arr, int $sort_flags = 0) { @@ -46,6 +49,7 @@ function array_unique(array $arr, int $sort_flags = 0) * @param array|null $arr4 * * @return array + * @psalm-pure */ function array_intersect(array $arr, array $arr2, array $arr3 = null, array $arr4 = null) { @@ -61,6 +65,7 @@ function array_intersect(array $arr, array $arr2, array $arr3 = null, array $arr * @param array|null $arr4 * * @return array + * @psalm-pure */ function array_intersect_key(array $arr, array $arr2, array $arr3 = null, array $arr4 = null) { @@ -75,6 +80,7 @@ function array_intersect_key(array $arr, array $arr2, array $arr3 = null, array * * @return array|false * @psalm-ignore-falsable-return + * @psalm-pure */ function array_combine(array $arr, array $arr2) { @@ -90,6 +96,7 @@ function array_combine(array $arr, array $arr2) * @param array|null $arr4 * * @return array + * @psalm-pure */ function array_diff(array $arr, array $arr2, array $arr3 = null, array $arr4 = null) { @@ -105,6 +112,7 @@ function array_diff(array $arr, array $arr2, array $arr3 = null, array $arr4 = n * @param array|null $arr4 * * @return array + * @psalm-pure */ function array_diff_key(array $arr, array $arr2, array $arr3 = null, array $arr4 = null) { @@ -117,6 +125,7 @@ function array_diff_key(array $arr, array $arr2, array $arr3 = null, array $arr4 * @param array $arr * * @return array + * @psalm-pure */ function array_flip(array $arr) { @@ -129,6 +138,7 @@ function array_flip(array $arr) * * @return TKey|null * @psalm-ignore-nullable-return + * @psalm-pure */ function key($arr) { @@ -140,6 +150,7 @@ function key($arr) * @param TValue $value * * @return array + * @psalm-pure */ function array_fill(int $start_index, int $num, $value) : array { @@ -153,6 +164,7 @@ function array_fill(int $start_index, int $num, $value) : array * @param bool $strict * * @return T|false + * @psalm-pure */ function array_search($needle, array $haystack, bool $strict = false) { @@ -164,6 +176,7 @@ function array_search($needle, array $haystack, bool $strict = false) * @param array $arr * @param callable(T,T):int $callback * @param-out array $arr + * @psalm-pure */ function usort(array &$arr, callable $callback): bool { @@ -175,6 +188,7 @@ function usort(array &$arr, callable $callback): bool * @param array $arr * * @return array + * @psalm-pure */ function array_change_key_case(array $arr, int $case = CASE_LOWER) { @@ -186,6 +200,7 @@ function array_change_key_case(array $arr, int $case = CASE_LOWER) * @param array $arr * * @return array> + * @psalm-pure */ function array_chunk(array $arr, int $size, bool $preserve_keys = false) { @@ -198,6 +213,7 @@ function array_chunk(array $arr, int $size, bool $preserve_keys = false) * @param array $search * * @return bool + * @psalm-pure */ function array_key_exists($key, array $search) : bool { @@ -211,6 +227,7 @@ function array_key_exists($key, array $search) : bool * @param array ...$arr2 * * @return array + * @psalm-pure */ function array_merge_recursive(array $arr, array ...$arr2) {