1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00
psalm/stubs/CoreGenericFunctions.phpstub

1599 lines
35 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* @psalm-template TArray as array
*
* @param TArray $array
* @param mixed $search_value
* @param bool $strict
2019-07-05 22:24:00 +02:00
*
* @return (TArray is non-empty-array ? non-empty-list<key-of<TArray>> : list<key-of<TArray>>)
* @psalm-pure
*/
function array_keys(array $array, $search_value = null, bool $strict = false)
2019-07-05 22:24:00 +02:00
{
}
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<TKey, TValue> $array
* @param array ...$arrays
2019-07-05 22:24:00 +02:00
*
* @return array<TKey, TValue>
* @psalm-pure
*/
function array_intersect(array $array, array ...$arrays)
2019-07-05 22:24:00 +02:00
{
}
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<TKey, TValue> $array
* @param array ...$arrays
2019-07-05 22:24:00 +02:00
*
* @return array<TKey, TValue>
* @psalm-pure
*/
function array_intersect_key(array $array, array ...$arrays)
2019-07-05 22:24:00 +02:00
{
}
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<TKey, TValue> $array
* @param array ...$arrays
*
* @return array<TKey, TValue>
* @psalm-pure
*/
function array_intersect_assoc(array $array, array ...$arrays)
{
}
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<mixed, TKey> $keys
* @param array<mixed, TValue> $values
2019-07-05 22:24:00 +02:00
*
* @return (
* PHP_MAJOR_VERSION is 8 ?
* ($keys is non-empty-array ? non-empty-array<TKey, TValue> : array<TKey, TValue>) :
* ($keys is non-empty-array ? non-empty-array<TKey, TValue>|false : array<TKey, TValue>|false)
* )
* @psalm-ignore-falsable-return
* @psalm-pure
*/
function array_combine(array $keys, array $values)
2019-07-05 22:24:00 +02:00
{
}
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<TKey, TValue> $array
* @param array ...$arrays
2019-07-05 22:24:00 +02:00
*
* @return array<TKey, TValue>
* @psalm-pure
*/
function array_diff(array $array, array ...$arrays)
2019-07-05 22:24:00 +02:00
{
}
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<TKey, TValue> $array
* @param array ...$arrays
2019-07-05 22:24:00 +02:00
*
* @return array<TKey, TValue>
* @psalm-pure
*/
function array_diff_key(array $array, array ...$arrays)
2019-07-05 22:24:00 +02:00
{
}
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<TKey, TValue> $array
* @param array ...$arrays
*
* @return array<TKey, TValue>
* @psalm-pure
*/
function array_diff_assoc(array $array, array ...$arrays)
{
}
2018-02-22 00:59:31 +01:00
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
2018-02-22 00:59:31 +01:00
*
* @param array<TKey, TValue> $array
2019-07-05 22:24:00 +02:00
*
2018-02-22 00:59:31 +01:00
* @return array<TValue, TKey>
* @psalm-pure
2018-02-22 00:59:31 +01:00
*/
function array_flip(array $array)
2019-07-05 22:24:00 +02:00
{
}
2018-02-22 00:59:31 +01:00
2018-04-05 06:21:14 +02:00
/**
* @psalm-template TKey as array-key
2020-07-15 15:49:30 +02:00
* @psalm-template TArray as array<TKey, mixed>
2018-04-05 06:21:14 +02:00
*
* @param TArray $array
2019-07-05 22:24:00 +02:00
*
* @return (TArray is array<never, never> ? null : (TArray is non-empty-list ? int<0,max> : (TArray is non-empty-array ? TKey : TKey|null)))
* @psalm-pure
2020-07-22 05:16:56 +02:00
* @psalm-ignore-nullable-return
2018-04-05 06:21:14 +02:00
*/
function key($array)
2019-07-05 22:24:00 +02:00
{
}
2018-04-05 06:21:14 +02:00
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
* @psalm-template TArray as array<TKey, TValue>
*
* @param TArray $array
*
* @return (TArray is array<never, never> ? false : (TArray is non-empty-array ? TValue : TValue|false))
* @psalm-pure
*/
function current($array)
{
}
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
* @psalm-template TArray as array<TKey, TValue>
*
* @param TArray $array
*
* @return (TArray is array<never, never> ? false : (TArray is non-empty-array ? TValue : TValue|false))
*/
function reset(&$array)
{
}
/**
* @psalm-template TKey as array-key
* @psalm-template TValue
* @psalm-template TArray as array<TKey, TValue>
*
* @param TArray $array
*
* @return (TArray is array<never, never> ? false : (TArray is non-empty-array ? TValue : TValue|false))
*/
function end(&$array)
{
}
/**
* @psalm-template TKey as array-key
2020-07-15 15:49:30 +02:00
* @psalm-template TArray as array<TKey, mixed>
*
* @param TArray $array
*
* @return (TArray is array<never, never> ? null : (TArray is non-empty-array ? key-of<TArray> : key-of<TArray>|null))
* @psalm-pure
*/
function array_key_first($array)
{
}
/**
* @psalm-template TArray as array
*
* @param TArray $array
*
* @return (TArray is array<never, never> ? null : (TArray is non-empty-array ? key-of<TArray> : key-of<TArray>|null))
* @psalm-pure
*/
function array_key_last($array)
{
}
/**
* @psalm-template TArray as array
*
* @param TArray $array
*
* @return (TArray is non-empty-array ? non-empty-list<value-of<TArray>> : list<value-of<TArray>>)
* @psalm-pure
*/
function array_values($array)
{
}
/**
* @psalm-template T
*
* @param mixed $needle
* @param array<T, mixed> $haystack
* @param bool $strict
2019-07-05 22:24:00 +02:00
*
* @return T|false
* @psalm-pure
*/
2019-07-05 22:24:00 +02:00
function array_search($needle, array $haystack, bool $strict = false)
{
}
2019-01-20 00:11:39 +01:00
2020-01-01 21:07:34 +01:00
/**
* @psalm-template T
* @psalm-template TArray as array<T>
2020-01-01 21:07:34 +01:00
*
* @param TArray $array
* @param-out (TArray is non-empty-array ? non-empty-list<T> : list<T>) $array
2020-01-01 21:07:34 +01:00
*/
function shuffle(array &$array): bool
2020-01-01 21:07:34 +01:00
{
}
2019-01-20 00:11:39 +01:00
/**
* @psalm-template T
2022-04-28 15:44:39 +02:00
* @psalm-template TArray as array<T>
2019-07-05 22:24:00 +02:00
*
2022-04-23 15:51:50 +02:00
* @param TArray $array
* @param-out (TArray is non-empty-array ? non-empty-list<T> : list<T>) $array
*/
function sort(array &$array, int $flags = SORT_REGULAR): bool
{
}
/**
* @psalm-template T
2022-04-28 16:01:17 +02:00
* @psalm-template TArray as array<T>
*
2022-04-28 16:01:17 +02:00
* @param TArray $array
* @param-out (TArray is non-empty-array ? non-empty-list<T> : list<T>) $array
*/
function rsort(array &$array, int $flags = SORT_REGULAR): bool
{
}
/**
* @psalm-template T
2022-04-28 17:36:28 +02:00
* @psalm-template TArray as array<T>
*
2022-04-28 17:36:28 +02:00
* @param TArray $array
2019-01-20 00:11:39 +01:00
* @param callable(T,T):int $callback
2022-04-28 17:36:28 +02:00
* @param-out (TArray is non-empty-array ? non-empty-list<T> : list<T>) $array
2019-01-20 00:11:39 +01:00
*/
function usort(array &$array, callable $callback): bool
2019-07-05 22:24:00 +02:00
{
}
2019-01-20 00:11:39 +01:00
2019-12-09 03:30:19 +01:00
/**
* @psalm-template TKey
* @psalm-template T
2022-04-28 16:49:32 +02:00
* @psalm-template TArray as array<TKey,T>
2019-12-09 03:30:19 +01:00
*
2022-04-28 16:49:32 +02:00
* @param TArray $array
2019-12-09 03:30:19 +01:00
* @param callable(T,T):int $callback
2022-04-28 16:49:32 +02:00
* @param-out (TArray is non-empty-array ? non-empty-array<TKey,T> : array<TKey,T>) $array
2019-12-09 03:30:19 +01:00
*/
function uasort(array &$array, callable $callback): bool
2019-12-09 03:30:19 +01:00
{
}
/**
* @psalm-template TKey
* @psalm-template T
2022-04-28 17:23:57 +02:00
* @psalm-template TArray as array<TKey,T>
*
2022-04-28 17:23:57 +02:00
* @param TArray $array
* @param callable(TKey,TKey):int $callback
2022-04-28 17:23:57 +02:00
* @param-out (TArray is non-empty-array ? non-empty-array<TKey,T> : array<TKey,T>) $array
*/
function uksort(array &$array, callable $callback): bool
{
}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @psalm-template K of array-key
* @psalm-template T
*
* @param array<K,T> $array
2019-07-05 22:24:00 +02:00
*
* @return array<K,T>
*/
function array_change_key_case(array $array, int $case = CASE_LOWER)
2019-07-05 22:24:00 +02:00
{
}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @psalm-template TKey as array-key
2019-07-05 22:24:00 +02:00
*
* @param TKey $key
* @param array<TKey, mixed> $array
2019-07-05 22:24:00 +02:00
*
* @return bool
*/
function array_key_exists($key, array $array) : bool
2019-07-05 22:24:00 +02:00
{
}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
2022-12-18 14:52:44 +01:00
* @no-named-arguments
*
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<TKey, TValue> ...$arrays
2019-07-05 22:24:00 +02:00
*
* @return array<TKey, TValue>
*/
function array_merge_recursive(array ...$arrays)
2019-07-05 22:24:00 +02:00
{
}
2022-12-18 14:50:51 +01:00
/**
* @psalm-pure
*
* @no-named-arguments
*
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<TKey, TValue> ...$arrays
*
* @return array<TKey, TValue>
*/
function array_merge(array ...$arrays)
{
}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @psalm-template TKey as array-key
* @psalm-template TValue
*
* @param array<TKey> $keys
* @param TValue $value
*
* @return array<TKey, TValue>
*/
function array_fill_keys(array $keys, $value): array
{
}
2019-12-29 17:05:08 +01:00
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @psalm-template TKey
2019-12-29 17:05:08 +01:00
*
* @param string $pattern
* @param array<TKey,string> $array
2019-12-29 17:05:08 +01:00
* @param 0|1 $flags 1=PREG_GREP_INVERT
* @return array<TKey,string>
*/
function preg_grep($pattern, array $array, $flags = 0)
2019-12-29 17:05:08 +01:00
{
}
/**
* @param resource $stream
2021-11-04 16:10:59 +01:00
* @param-out closed-resource $stream
*/
function fclose(&$stream) : bool
{
}
/**
* @psalm-pure
* @template T as string
* @param T $string
* @return (T is non-empty-string ? non-empty-string : string)
*/
function sodium_bin2base64(string $string, int $id): string
/**
* @psalm-pure
* @template T as string
* @param T $string
* @return (T is non-empty-string ? non-empty-string : string)
*/
function sodium_bin2hex(string $string): string {}
/**
* @param string $string
2021-11-04 16:10:59 +01:00
* @param-out null $string
*/
function sodium_memzero(string &$string): void
{
}
/**
* @param mixed $value
* @param bool $return
* @return ($return is true ? string : void)
2020-05-22 04:47:58 +02:00
*
* @psalm-taint-specialize
2021-11-04 16:10:59 +01:00
* @psalm-flow ($value) -> return
* @psalm-taint-sink html $value
*/
function var_export($value, bool $return = false) {}
/**
* @param mixed $value
* @param list<mixed> $values
* @return string
*
* @psalm-taint-specialize
* @psalm-flow ($value, $values) -> return
* @psalm-taint-sink html $value
* @psalm-taint-sink html $values
*/
function var_dump($value, ...$values) {}
/**
* @param mixed $value
* @param bool $return
* @return ($return is true ? string : true)
2020-05-22 04:47:58 +02:00
*
* @psalm-taint-specialize
2021-11-04 16:10:59 +01:00
* @psalm-flow ($value) -> return
* @psalm-taint-sink html $value
*/
function print_r($value, bool $return = false) {}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @psalm-taint-sink file $filename
* @param mixed $filename
* @return ($return is true ? string : bool)
*/
function highlight_file($filename, bool $return = false) {}
/**
* @psalm-pure
*
* @psalm-taint-sink file $filename
* @param mixed $filename
* @return ($return is true ? string : bool)
*/
function show_source($filename, bool $return = false) {}
/**
* @psalm-pure
*
* @psalm-taint-sink file $filename
*/
function php_strip_whitespace(string $filename) : string {}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @param mixed $string
* @return ($return is true ? string : bool)
2020-05-22 04:47:58 +02:00
*
2021-11-04 16:10:59 +01:00
* @psalm-flow ($string) -> return
*/
function highlight_string($string, bool $return = false) {}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @return ($as_float is true ? float : string)
*/
function microtime(bool $as_float = false) {}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @return ($as_float is true ? float : array<string, int>)
*/
function gettimeofday(bool $as_float = false) {}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @param numeric $num
* @return ($num is int ? positive-int|0 : ($num is float ? float : positive-int|0|float))
*/
function abs($num) {}
2020-04-08 01:59:20 +02:00
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
2020-04-08 01:59:20 +02:00
* @template T as string|int|float
* @template TStep as int|float
* @param T $start
* @param T $end
* @param TStep $step
* @return (
* T is int
* ? (TStep is int ? non-empty-list<int> : non-empty-list<float>)
2020-04-08 01:59:20 +02:00
* : (
* T is float
* ? non-empty-list<float>
2020-04-08 01:59:20 +02:00
* : (
* T is string
* ? non-empty-list<string>
2020-04-08 01:59:20 +02:00
* : (
* T is int|float
* ? non-empty-list<int|float>
* : non-empty-list<int|float|string>
2020-04-08 01:59:20 +02:00
* )
* )
* )
* )
*/
function range($start, $end, $step = 1) {}
2020-04-15 03:07:44 +02:00
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
2020-04-15 03:07:44 +02:00
* @return (
* $format is 'd'|'j'|'N'|'w'|'z'|'W'|'m'|'n'|'t'|'L'|'o'|'Y'|'y'|'B'|'g'|'G'|'h'|'H'|'i'|'s'|'u'|'v'|'Z'|'U'|'I'
* ? numeric-string
* : ($timestamp is numeric ? string : string|false)
* )
*/
function date(string $format, int $timestamp = 0) {}
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
* @param mixed $vars
* @param-out string|int|float|null $vars
* @psalm-flow ($string, $format) -> return
* @return (func_num_args() is 2 ? (null|list<float|int|string|null>) : int)
*/
function sscanf(string $string, string $format, &...$vars) {}
2020-05-11 17:36:50 +02:00
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
2020-05-11 17:36:50 +02:00
* @return (
* func_num_args() is 1
* ? array{dirname: string, basename: string, extension?: string, filename: string}
2020-05-11 17:36:50 +02:00
* : string
* )
*/
function pathinfo(string $path, int $flags = \PATHINFO_DIRNAME) {}
2020-05-11 17:36:50 +02:00
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
2020-05-11 17:36:50 +02:00
* @return (func_num_args() is 0 ? array<string, string> : string|false)
*/
function getenv(string $varname = '', bool $local_only = false) {}
2020-05-15 16:18:05 +02:00
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
2020-05-15 16:18:05 +02:00
* @return (
* $string is non-empty-string ? non-empty-lowercase-string : lowercase-string
2020-05-15 16:18:05 +02:00
* )
2020-05-22 04:47:58 +02:00
*
* @psalm-flow ($string) -> return
2020-05-15 16:18:05 +02:00
*/
function strtolower(string $string) : string {}
2020-05-15 16:18:05 +02:00
/**
2020-05-22 04:47:58 +02:00
* @psalm-pure
*
2021-07-15 20:15:08 +02:00
* @return (
* $string is non-falsy-string
2021-07-15 20:40:18 +02:00
* ? non-falsy-string
* : ($string is non-empty-string ? non-empty-string : string)
2021-07-15 20:15:08 +02:00
* )
*
* @psalm-flow ($string) -> return
2020-05-22 04:47:58 +02:00
*/
function strtoupper(string $string) : string {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* @param string|array<string> $string
* @param string|array<string> $replace
* @param int|array<int> $offset
* @param null|int|array<int> $length
*
2020-11-24 16:44:33 +01:00
* @return ($string is array<string> ? array<string> : string)
*
* @psalm-flow ($string, $replace) -> return
*/
function substr_replace($string, $replace, $offset, $length = null) {}
/**
* @psalm-pure
*
2020-09-01 23:23:26 +02:00
* @param string $haystack
*
* @psalm-return positive-int|0|false
*/
2020-09-01 23:23:26 +02:00
function strpos($haystack, $needle, int $offset = 0) : int {}
2020-06-22 23:53:03 +02:00
/**
* @psalm-pure
*
* @return (
* $string is class-string
* ? ($characters is '\\' ? class-string : string)
* : ($string is lowercase-string ? lowercase-string : string)
* )
*
2021-10-07 20:10:36 +02:00
* @psalm-flow ($string) -> return
2020-06-22 23:53:03 +02:00
*/
2021-10-07 20:10:36 +02:00
function trim(string $string, string $characters = " \t\n\r\0\x0B") : string {}
2020-06-22 23:53:03 +02:00
/**
* @psalm-pure
*
* @return (
* $string is class-string
* ? ($characters is '\\' ? class-string : string)
* : ($string is lowercase-string ? lowercase-string : string)
* )
*
2021-10-07 20:10:36 +02:00
* @psalm-flow ($string) -> return
2020-06-22 23:53:03 +02:00
*/
2021-10-07 20:10:36 +02:00
function ltrim(string $string, string $characters = " \t\n\r\0\x0B") : string {}
2020-06-22 23:53:03 +02:00
/**
* @psalm-pure
*
* @return ($string is lowercase-string ? lowercase-string : string)
*
2021-10-07 20:10:36 +02:00
* @psalm-flow ($string) -> return
2020-06-22 23:53:03 +02:00
*/
2021-10-07 20:10:36 +02:00
function rtrim(string $string, string $characters = " \t\n\r\0\x0B") : string {}
2020-06-22 23:53:03 +02:00
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* @param string|array $separator
* @param array<string|float|int|stringable-object|null|bool> $array
2020-05-15 16:18:05 +02:00
*
* @return (
* $separator is non-empty-string
* ? ($array is non-empty-array
* ? ($array is array<literal-string|literal-int>
* ? ($separator is literal-string ? non-empty-literal-string : non-empty-string)
* : non-empty-string
* )
2020-05-15 16:18:05 +02:00
* : string)
* : ($array is non-empty-array
* ? ($array is array<non-empty-literal-string|non-empty-string>
* ? ($array is array<non-empty-literal-string> ? non-empty-literal-string : non-empty-string)
* : string
* )
* : string)
2020-05-15 16:18:05 +02:00
* )
2020-05-22 04:47:58 +02:00
*
* @psalm-flow ($separator) -> return
* @psalm-flow ($array) -(array-fetch)-> return
2020-05-15 16:18:05 +02:00
*/
function implode($separator, array $array = []) : string {}
2020-05-18 23:23:21 +02:00
/**
* @psalm-pure
*
* @param string|array $separator
* @param array<string|float|int|stringable-object|null|bool> $array
*
* @return (
* $separator is non-empty-string
* ? ($array is non-empty-array
* ? ($array is array<literal-string|literal-int>
* ? ($separator is literal-string ? non-empty-literal-string : non-empty-string)
* : non-empty-string
* )
* : string)
2022-05-14 16:47:46 +02:00
* : ($array is non-empty-array
* ? ($array is array<non-empty-literal-string|non-empty-string>
* ? ($array is array<non-empty-literal-string> ? non-empty-literal-string : non-empty-string)
* : string
* )
* : string)
* )
*
* @psalm-flow ($separator) -> return
* @psalm-flow ($array) -(array-fetch)-> return
*/
function join($separator, array $array = []): string
{
}
2020-06-22 23:53:03 +02:00
/**
* @psalm-pure
*
Refined `explode()` types Fixes #5039 This patch removes the need for a custom function return type provider for `explode()`, and instead replaces all that with a single stub for the `explode()` function, which provides types for some of the most common `$limit` input values. With this change, the `$delimiter` is enforced to be a `non-empty-string`, which will lead to downstream consumers having to adjust some code accordingly, but that shouldn't affect the most common scenario of exploding a string based with a constant `literal-string` delimiter, which most PHP devs tend to do. This change didn't come with an accompanying test, since that would be a bit wasteful, but it was verified locally with following script: ```php <?php $possible0 = explode(',', 'hello, world', -100); $possible1 = explode(',', 'hello, world', -1); $possible2 = explode(',', 'hello, world', 0); $possible3 = explode(',', 'hello, world', 1); $possible4 = explode(',', 'hello, world', 2); $possible5 = explode(',', 'hello, world', 3); $possible6 = explode(',', 'hello, world', 4); try { $impossible1 = explode('', '', -1); } catch (Throwable $impossible1) {} $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; /** @psalm-trace $traced */ var_dump($traced); return $traced; ``` Running psalm locally, this produces: ``` psalm on  feature/#5039-more-refined-types-for-explode-core-function [?] via 🐘 v8.1.13 via ❄️ impure (nix-shell) ❯ ./psalm --no-cache explode.php Target PHP version: 7.4 (inferred from composer.json) Extensions enabled: dom, simplexml (unsupported extensions: ctype, json, libxml, mbstring, tokenizer) Scanning files... Analyzing files... ░ To whom it may concern: Psalm cannot detect unused classes, methods and properties when analyzing individual files and folders. Run on the full project to enable complete unused code detection. ERROR: InvalidArgument - explode.php:11:28 - Argument 1 of explode expects non-empty-string, but '' provided (see https://psalm.dev/004) $impossible1 = explode('', '', -1); ERROR: PossiblyUndefinedGlobalVariable - explode.php:14:96 - Possibly undefined global variable $impossible1 defined in try block (see https://psalm.dev/126) $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; ERROR: ForbiddenCode - explode.php:18:1 - Unsafe var_dump (see https://psalm.dev/002) /** @psalm-trace $traced */ var_dump($traced); ERROR: Trace - explode.php:18:1 - $traced: list{0: array<never, never>, 1: non-empty-list<string>, 2: list{string}, 3: list{string}, 4: array{0: string, 1?: string}, 5: array{0: string, 1?: string, 2?: string}, 6: non-empty-list<string>, 7?: Throwable|non-empty-list<string>} (see https://psalm.dev/224) /** @psalm-trace $traced */ var_dump($traced); ------------------------------ 4 errors found ------------------------------ Checks took 6.31 seconds and used 265.386MB of memory Psalm was unable to infer types in the codebase ``` The actual runtime behavior on PHP 8.x: https://3v4l.org/0NKlW ``` array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> object(ValueError)#1 (7) { ["message":protected]=> string(51) "explode(): Argument #1 ($separator) cannot be empty" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/0NKlW" ["line":protected]=> int(11) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/0NKlW" ["line"]=> int(11) ["function"]=> string(7) "explode" ["args"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> int(-1) } } } ["previous":"Error":private]=> NULL } } ``` On PHP 7: ``` Warning: explode(): Empty delimiter in /in/0NKlW on line 11 array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> bool(false) } ```
2022-12-28 17:01:46 +01:00
* @param non-empty-string $separator
*
* @return (
* $string is lowercase-string
* ? (
* $limit is int<min, -2>
* ? list<empty>
* : (
* $limit is int<0, 1>
* ? list{lowercase-string}
* : (
* $limit is 2
* ? list{0: lowercase-string, 1?: lowercase-string}
* : (
* $limit is 3
* ? list{0: lowercase-string, 1?: lowercase-string, 2?: lowercase-string}
* : non-empty-list<lowercase-string>
* )
* )
* )
* )
Refined `explode()` types Fixes #5039 This patch removes the need for a custom function return type provider for `explode()`, and instead replaces all that with a single stub for the `explode()` function, which provides types for some of the most common `$limit` input values. With this change, the `$delimiter` is enforced to be a `non-empty-string`, which will lead to downstream consumers having to adjust some code accordingly, but that shouldn't affect the most common scenario of exploding a string based with a constant `literal-string` delimiter, which most PHP devs tend to do. This change didn't come with an accompanying test, since that would be a bit wasteful, but it was verified locally with following script: ```php <?php $possible0 = explode(',', 'hello, world', -100); $possible1 = explode(',', 'hello, world', -1); $possible2 = explode(',', 'hello, world', 0); $possible3 = explode(',', 'hello, world', 1); $possible4 = explode(',', 'hello, world', 2); $possible5 = explode(',', 'hello, world', 3); $possible6 = explode(',', 'hello, world', 4); try { $impossible1 = explode('', '', -1); } catch (Throwable $impossible1) {} $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; /** @psalm-trace $traced */ var_dump($traced); return $traced; ``` Running psalm locally, this produces: ``` psalm on  feature/#5039-more-refined-types-for-explode-core-function [?] via 🐘 v8.1.13 via ❄️ impure (nix-shell) ❯ ./psalm --no-cache explode.php Target PHP version: 7.4 (inferred from composer.json) Extensions enabled: dom, simplexml (unsupported extensions: ctype, json, libxml, mbstring, tokenizer) Scanning files... Analyzing files... ░ To whom it may concern: Psalm cannot detect unused classes, methods and properties when analyzing individual files and folders. Run on the full project to enable complete unused code detection. ERROR: InvalidArgument - explode.php:11:28 - Argument 1 of explode expects non-empty-string, but '' provided (see https://psalm.dev/004) $impossible1 = explode('', '', -1); ERROR: PossiblyUndefinedGlobalVariable - explode.php:14:96 - Possibly undefined global variable $impossible1 defined in try block (see https://psalm.dev/126) $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; ERROR: ForbiddenCode - explode.php:18:1 - Unsafe var_dump (see https://psalm.dev/002) /** @psalm-trace $traced */ var_dump($traced); ERROR: Trace - explode.php:18:1 - $traced: list{0: array<never, never>, 1: non-empty-list<string>, 2: list{string}, 3: list{string}, 4: array{0: string, 1?: string}, 5: array{0: string, 1?: string, 2?: string}, 6: non-empty-list<string>, 7?: Throwable|non-empty-list<string>} (see https://psalm.dev/224) /** @psalm-trace $traced */ var_dump($traced); ------------------------------ 4 errors found ------------------------------ Checks took 6.31 seconds and used 265.386MB of memory Psalm was unable to infer types in the codebase ``` The actual runtime behavior on PHP 8.x: https://3v4l.org/0NKlW ``` array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> object(ValueError)#1 (7) { ["message":protected]=> string(51) "explode(): Argument #1 ($separator) cannot be empty" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/0NKlW" ["line":protected]=> int(11) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/0NKlW" ["line"]=> int(11) ["function"]=> string(7) "explode" ["args"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> int(-1) } } } ["previous":"Error":private]=> NULL } } ``` On PHP 7: ``` Warning: explode(): Empty delimiter in /in/0NKlW on line 11 array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> bool(false) } ```
2022-12-28 17:01:46 +01:00
* : (
* $limit is int<min, -2>
* ? list<empty>
Refined `explode()` types Fixes #5039 This patch removes the need for a custom function return type provider for `explode()`, and instead replaces all that with a single stub for the `explode()` function, which provides types for some of the most common `$limit` input values. With this change, the `$delimiter` is enforced to be a `non-empty-string`, which will lead to downstream consumers having to adjust some code accordingly, but that shouldn't affect the most common scenario of exploding a string based with a constant `literal-string` delimiter, which most PHP devs tend to do. This change didn't come with an accompanying test, since that would be a bit wasteful, but it was verified locally with following script: ```php <?php $possible0 = explode(',', 'hello, world', -100); $possible1 = explode(',', 'hello, world', -1); $possible2 = explode(',', 'hello, world', 0); $possible3 = explode(',', 'hello, world', 1); $possible4 = explode(',', 'hello, world', 2); $possible5 = explode(',', 'hello, world', 3); $possible6 = explode(',', 'hello, world', 4); try { $impossible1 = explode('', '', -1); } catch (Throwable $impossible1) {} $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; /** @psalm-trace $traced */ var_dump($traced); return $traced; ``` Running psalm locally, this produces: ``` psalm on  feature/#5039-more-refined-types-for-explode-core-function [?] via 🐘 v8.1.13 via ❄️ impure (nix-shell) ❯ ./psalm --no-cache explode.php Target PHP version: 7.4 (inferred from composer.json) Extensions enabled: dom, simplexml (unsupported extensions: ctype, json, libxml, mbstring, tokenizer) Scanning files... Analyzing files... ░ To whom it may concern: Psalm cannot detect unused classes, methods and properties when analyzing individual files and folders. Run on the full project to enable complete unused code detection. ERROR: InvalidArgument - explode.php:11:28 - Argument 1 of explode expects non-empty-string, but '' provided (see https://psalm.dev/004) $impossible1 = explode('', '', -1); ERROR: PossiblyUndefinedGlobalVariable - explode.php:14:96 - Possibly undefined global variable $impossible1 defined in try block (see https://psalm.dev/126) $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; ERROR: ForbiddenCode - explode.php:18:1 - Unsafe var_dump (see https://psalm.dev/002) /** @psalm-trace $traced */ var_dump($traced); ERROR: Trace - explode.php:18:1 - $traced: list{0: array<never, never>, 1: non-empty-list<string>, 2: list{string}, 3: list{string}, 4: array{0: string, 1?: string}, 5: array{0: string, 1?: string, 2?: string}, 6: non-empty-list<string>, 7?: Throwable|non-empty-list<string>} (see https://psalm.dev/224) /** @psalm-trace $traced */ var_dump($traced); ------------------------------ 4 errors found ------------------------------ Checks took 6.31 seconds and used 265.386MB of memory Psalm was unable to infer types in the codebase ``` The actual runtime behavior on PHP 8.x: https://3v4l.org/0NKlW ``` array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> object(ValueError)#1 (7) { ["message":protected]=> string(51) "explode(): Argument #1 ($separator) cannot be empty" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/0NKlW" ["line":protected]=> int(11) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/0NKlW" ["line"]=> int(11) ["function"]=> string(7) "explode" ["args"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> int(-1) } } } ["previous":"Error":private]=> NULL } } ``` On PHP 7: ``` Warning: explode(): Empty delimiter in /in/0NKlW on line 11 array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> bool(false) } ```
2022-12-28 17:01:46 +01:00
* : (
* $limit is int<0, 1>
* ? list{string}
Refined `explode()` types Fixes #5039 This patch removes the need for a custom function return type provider for `explode()`, and instead replaces all that with a single stub for the `explode()` function, which provides types for some of the most common `$limit` input values. With this change, the `$delimiter` is enforced to be a `non-empty-string`, which will lead to downstream consumers having to adjust some code accordingly, but that shouldn't affect the most common scenario of exploding a string based with a constant `literal-string` delimiter, which most PHP devs tend to do. This change didn't come with an accompanying test, since that would be a bit wasteful, but it was verified locally with following script: ```php <?php $possible0 = explode(',', 'hello, world', -100); $possible1 = explode(',', 'hello, world', -1); $possible2 = explode(',', 'hello, world', 0); $possible3 = explode(',', 'hello, world', 1); $possible4 = explode(',', 'hello, world', 2); $possible5 = explode(',', 'hello, world', 3); $possible6 = explode(',', 'hello, world', 4); try { $impossible1 = explode('', '', -1); } catch (Throwable $impossible1) {} $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; /** @psalm-trace $traced */ var_dump($traced); return $traced; ``` Running psalm locally, this produces: ``` psalm on  feature/#5039-more-refined-types-for-explode-core-function [?] via 🐘 v8.1.13 via ❄️ impure (nix-shell) ❯ ./psalm --no-cache explode.php Target PHP version: 7.4 (inferred from composer.json) Extensions enabled: dom, simplexml (unsupported extensions: ctype, json, libxml, mbstring, tokenizer) Scanning files... Analyzing files... ░ To whom it may concern: Psalm cannot detect unused classes, methods and properties when analyzing individual files and folders. Run on the full project to enable complete unused code detection. ERROR: InvalidArgument - explode.php:11:28 - Argument 1 of explode expects non-empty-string, but '' provided (see https://psalm.dev/004) $impossible1 = explode('', '', -1); ERROR: PossiblyUndefinedGlobalVariable - explode.php:14:96 - Possibly undefined global variable $impossible1 defined in try block (see https://psalm.dev/126) $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; ERROR: ForbiddenCode - explode.php:18:1 - Unsafe var_dump (see https://psalm.dev/002) /** @psalm-trace $traced */ var_dump($traced); ERROR: Trace - explode.php:18:1 - $traced: list{0: array<never, never>, 1: non-empty-list<string>, 2: list{string}, 3: list{string}, 4: array{0: string, 1?: string}, 5: array{0: string, 1?: string, 2?: string}, 6: non-empty-list<string>, 7?: Throwable|non-empty-list<string>} (see https://psalm.dev/224) /** @psalm-trace $traced */ var_dump($traced); ------------------------------ 4 errors found ------------------------------ Checks took 6.31 seconds and used 265.386MB of memory Psalm was unable to infer types in the codebase ``` The actual runtime behavior on PHP 8.x: https://3v4l.org/0NKlW ``` array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> object(ValueError)#1 (7) { ["message":protected]=> string(51) "explode(): Argument #1 ($separator) cannot be empty" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/0NKlW" ["line":protected]=> int(11) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/0NKlW" ["line"]=> int(11) ["function"]=> string(7) "explode" ["args"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> int(-1) } } } ["previous":"Error":private]=> NULL } } ``` On PHP 7: ``` Warning: explode(): Empty delimiter in /in/0NKlW on line 11 array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> bool(false) } ```
2022-12-28 17:01:46 +01:00
* : (
* $limit is 2
* ? list{0: string, 1?: string}
* : (
* $limit is 3
* ? list{0: string, 1?: string, 2?: string}
* : non-empty-list<string>
* )
Refined `explode()` types Fixes #5039 This patch removes the need for a custom function return type provider for `explode()`, and instead replaces all that with a single stub for the `explode()` function, which provides types for some of the most common `$limit` input values. With this change, the `$delimiter` is enforced to be a `non-empty-string`, which will lead to downstream consumers having to adjust some code accordingly, but that shouldn't affect the most common scenario of exploding a string based with a constant `literal-string` delimiter, which most PHP devs tend to do. This change didn't come with an accompanying test, since that would be a bit wasteful, but it was verified locally with following script: ```php <?php $possible0 = explode(',', 'hello, world', -100); $possible1 = explode(',', 'hello, world', -1); $possible2 = explode(',', 'hello, world', 0); $possible3 = explode(',', 'hello, world', 1); $possible4 = explode(',', 'hello, world', 2); $possible5 = explode(',', 'hello, world', 3); $possible6 = explode(',', 'hello, world', 4); try { $impossible1 = explode('', '', -1); } catch (Throwable $impossible1) {} $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; /** @psalm-trace $traced */ var_dump($traced); return $traced; ``` Running psalm locally, this produces: ``` psalm on  feature/#5039-more-refined-types-for-explode-core-function [?] via 🐘 v8.1.13 via ❄️ impure (nix-shell) ❯ ./psalm --no-cache explode.php Target PHP version: 7.4 (inferred from composer.json) Extensions enabled: dom, simplexml (unsupported extensions: ctype, json, libxml, mbstring, tokenizer) Scanning files... Analyzing files... ░ To whom it may concern: Psalm cannot detect unused classes, methods and properties when analyzing individual files and folders. Run on the full project to enable complete unused code detection. ERROR: InvalidArgument - explode.php:11:28 - Argument 1 of explode expects non-empty-string, but '' provided (see https://psalm.dev/004) $impossible1 = explode('', '', -1); ERROR: PossiblyUndefinedGlobalVariable - explode.php:14:96 - Possibly undefined global variable $impossible1 defined in try block (see https://psalm.dev/126) $traced = [$possible0, $possible1, $possible2, $possible3, $possible4, $possible5, $possible6, $impossible1]; ERROR: ForbiddenCode - explode.php:18:1 - Unsafe var_dump (see https://psalm.dev/002) /** @psalm-trace $traced */ var_dump($traced); ERROR: Trace - explode.php:18:1 - $traced: list{0: array<never, never>, 1: non-empty-list<string>, 2: list{string}, 3: list{string}, 4: array{0: string, 1?: string}, 5: array{0: string, 1?: string, 2?: string}, 6: non-empty-list<string>, 7?: Throwable|non-empty-list<string>} (see https://psalm.dev/224) /** @psalm-trace $traced */ var_dump($traced); ------------------------------ 4 errors found ------------------------------ Checks took 6.31 seconds and used 265.386MB of memory Psalm was unable to infer types in the codebase ``` The actual runtime behavior on PHP 8.x: https://3v4l.org/0NKlW ``` array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> object(ValueError)#1 (7) { ["message":protected]=> string(51) "explode(): Argument #1 ($separator) cannot be empty" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/0NKlW" ["line":protected]=> int(11) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/0NKlW" ["line"]=> int(11) ["function"]=> string(7) "explode" ["args"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> int(-1) } } } ["previous":"Error":private]=> NULL } } ``` On PHP 7: ``` Warning: explode(): Empty delimiter in /in/0NKlW on line 11 array(8) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(5) "hello" } [2]=> array(1) { [0]=> string(12) "hello, world" } [3]=> array(1) { [0]=> string(12) "hello, world" } [4]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [5]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [6]=> array(2) { [0]=> string(5) "hello" [1]=> string(6) " world" } [7]=> bool(false) } ```
2022-12-28 17:01:46 +01:00
* )
* )
* )
* )
*
2020-06-22 23:53:03 +02:00
* @psalm-flow ($string) -(array-assignment)-> return
*/
function explode(string $separator, string $string, int $limit = -1) : array {}
2020-06-22 23:53:03 +02:00
2020-10-12 19:04:28 +02:00
/**
* @psalm-pure
*
* @psalm-flow ($subject) -(array-assignment)-> return
*
* @template TFlags as int-mask<0, 1, 2, 4>
2020-10-13 02:25:46 +02:00
*
* @param TFlags $flags
*
* @return (TFlags is 0|2 ? non-empty-list<string>|false : (TFlags is 1|3 ? list<string>|false : list<array{string,int}>|false))
2020-10-12 19:04:28 +02:00
*
* @psalm-ignore-falsable-return
*/
function preg_split(string $pattern, string $subject, int $limit = -1, int $flags = 0) {}
2020-05-18 23:23:21 +02:00
/**
* @param array $array
2020-05-18 23:23:21 +02:00
*
* @return (
* $array is array<int>
2020-05-22 04:47:58 +02:00
* ? int
* : ($array is array<float>
2020-05-18 23:23:21 +02:00
* ? float
* : float|int
* )
* )
*/
function array_sum(array $array) {}
2020-05-22 04:47:58 +02:00
/**
* @param array $array
*
* @return (
* $array is array<int>
* ? int
* : ($array is array<float>
* ? float
* : float|int
* )
* )
*/
function array_product(array $array) {}
/**
* 257 is FILTER_VALIDATE_INT
* @psalm-taint-escape ($filter is 257 ? 'html' : null)
*
* 258 is FILTER_VALIDATE_BOOLEAN
* @psalm-taint-escape ($filter is 258 ? 'html' : null)
*
* 259 is FILTER_VALIDATE_FLOAT
* @psalm-taint-escape ($filter is 259 ? 'html' : null)
*
* 519 is FILTER_SANITIZE_NUMBER_INT
* @psalm-taint-escape ($filter is 519 ? 'html' : null)
*
* 520 is FILTER_SANITIZE_NUMBER_FLOAT
* @psalm-taint-escape ($filter is 520 ? 'html' : null)
*
* @psalm-flow ($value, $filter, $options) -> return
*/
function filter_var(mixed $value, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
2020-06-22 23:53:03 +02:00
* @psalm-taint-escape html
* @psalm-flow ($string) -> return
2020-05-22 04:47:58 +02:00
*/
function strip_tags(string $string, ?string $allowed_tags = null) : string {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function stripcslashes(string $string) : string {}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function stripslashes(string $string) : string {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* Tainting is handled in a plugin
2020-05-22 04:47:58 +02:00
*
* @psalm-flow ($string) -> return
*/
function htmlentities(string $string, ?int $flags = null, ?string $encoding = null, bool $double_encode = true) : string {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* Tainting is handled in a plugin
2020-05-22 04:47:58 +02:00
*
* @psalm-flow ($string) -> return
*/
function html_entity_decode(string $string, ?int $flags = null, ?string $encoding = null) : string {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* Tainting is handled in a plugin
2020-05-22 04:47:58 +02:00
*
* @psalm-flow ($string) -> return
* @psalm-return (
* $string is non-empty-string
* ? non-empty-string
* : string
* )
2020-05-22 04:47:58 +02:00
*/
2021-05-24 01:12:02 +02:00
function htmlspecialchars(string $string, int $flags = ENT_COMPAT | ENT_HTML401, ?string $encoding = 'UTF-8', bool $double_encode = true) : string {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* Tainting is handled in a plugin
2020-05-22 04:47:58 +02:00
*
* @psalm-flow ($string) -> return
*/
function htmlspecialchars_decode(string $string, ?int $flags = null) : string {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* @psalm-taint-escape html
* @psalm-taint-escape has_quotes
* @psalm-flow ($string) -> return
*/
function urlencode(string $string) : string {}
2021-05-19 21:20:56 +02:00
/**
* @psalm-pure
*
2021-05-19 21:20:56 +02:00
* @psalm-return (
* $string is ''
* ? 0
* : (
* $string is non-empty-string
* ? positive-int
* : (0|positive-int)
* )
2021-05-19 21:20:56 +02:00
* )
*/
function strlen(string $string) : int {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* @param string|array<string|int|float> $search
* @param string|array<string|int|float> $replace
* @param string|array<string|int|float> $subject
2020-05-22 04:47:58 +02:00
* @param int $count
* @return ($subject is array ? array<string> : string)
2020-05-22 04:47:58 +02:00
*
* @psalm-flow ($replace, $subject) -> return
*/
function str_replace($search, $replace, $subject, &$count = null) {}
/**
* @psalm-pure
*
* @param string|array<string|int|float> $search
* @param string|array<string|int|float> $replace
* @param string|array<string|int|float> $subject
* @param int $count
* @return ($subject is array ? array<string> : string)
*
* @psalm-flow ($replace, $subject) -> return
*/
function str_ireplace($search, $replace, $subject, &$count = null) {}
/**
* @psalm-pure
*
* @return ($string is non-empty-string ? non-empty-string : ($length is positive-int ? non-empty-string: string))
*
* @psalm-flow ($string, $pad_string) -> return
*/
function str_pad(string $string, int $length, $pad_string = '', int $pad_type = STR_PAD_RIGHT): string {}
/**
* @psalm-pure
*
* @todo update $times to be `0|positive-int`
* @return (
* $string is non-empty-string
* ? (
* $times is positive-int
* ? non-empty-string
* : ($times is 0 ? '' : string)
* )
* : ($times is 0 ? '' : string)
* )
*
* @psalm-flow ($string) -> return
*/
function str_repeat(string $string, int $times): string {}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function str_rot13(string $string): string {}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function str_shuffle(string $string): string {}
/**
* @psalm-pure
* @return ($length is positive-int ? list<string> : false)
*
* @psalm-flow ($string) -> return
*/
function str_split(string $string, int $length = 1) {}
/**
* @psalm-pure
2020-11-25 17:49:51 +01:00
* @return string|false
* @psalm-ignore-falsable-return
*
* @psalm-flow ($haystack) -> return
*/
2020-11-25 17:49:51 +01:00
function strstr(string $haystack, string $needle, bool $before_needle = false) {}
/**
* @psalm-pure
2020-11-25 17:49:51 +01:00
* @return string|false
* @psalm-ignore-falsable-return
*
* @psalm-flow ($haystack) -> return
*/
2020-11-25 17:49:51 +01:00
function stristr(string $haystack, string $needle, bool $before_needle = false) {}
/**
* @psalm-pure
2020-11-24 16:44:33 +01:00
* @return string|false
2020-11-25 17:49:51 +01:00
* @psalm-ignore-falsable-return
*
* @psalm-flow ($haystack) -> return
*/
2020-11-24 16:44:33 +01:00
function strchr(string $haystack, string $needle, bool $before_needle = false) {}
/**
* @psalm-pure
2020-11-24 16:44:33 +01:00
* @return string|false
2020-11-25 17:49:51 +01:00
* @psalm-ignore-falsable-return
*
* @psalm-flow ($string) -> return
*/
function strpbrk(string $string, string $characters) {}
/**
* @psalm-pure
2020-11-24 16:44:33 +01:00
* @return string|false
2020-11-25 17:49:51 +01:00
* @psalm-ignore-falsable-return
*
* @psalm-flow ($haystack) -> return
*/
2020-11-25 17:49:51 +01:00
function strrchr(string $haystack, string $needle) {}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function strrev(string $string): string {}
/**
* @psalm-pure
*
* @param 0|1|2 $format
* @return (
* $format is 0 ?
* int :
* (
* $format is 1 ?
* list<string> :
* array<int, string>
* )
* )
*/
function str_word_count(string $string, int $format = 0, string|null $characters = null) {}
2020-11-17 21:15:29 +01:00
/**
* @psalm-pure
*
* @param string|string[] $pattern
* @param string|array<string|int|float> $replacement
* @param string|array<string|int|float> $subject
* @param int $count
2021-09-07 23:02:28 +02:00
* @return ($subject is array ? array<string> : string|null)
2020-11-17 21:15:29 +01:00
*
* @psalm-flow ($replacement, $subject) -> return
*/
function preg_filter($pattern, $replacement, $subject, int $limit = -1, &$count = null) {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* @param string|string[] $pattern
* @param string|array<string|int|float> $replacement
* @param string|array<string|int|float> $subject
2020-05-22 04:47:58 +02:00
* @param int $count
* @return ($subject is array ? array<string>|null : string|null)
2020-05-22 04:47:58 +02:00
*
2021-11-04 16:10:59 +01:00
* @psalm-flow ($replacement, $subject) -> return
2020-05-22 04:47:58 +02:00
*/
function preg_replace($pattern, $replacement, $subject, int $limit = -1, &$count = null) {}
2020-05-22 04:47:58 +02:00
/**
* @param string|string[] $pattern
* @param callable(string[]):string $callback
* @param string|array<string|int|float> $subject
* @param int $count
* @return ($subject is array ? array<string>|null : string|null)
*
* @psalm-taint-specialize
* @psalm-flow ($subject) -> return
*/
function preg_replace_callback($pattern, $callback, $subject, int $limit = -1, &$count = null, int $flags = 0) {}
/**
* @psalm-pure
* @template TFlags as int
*
* @param string $pattern
* @param string $subject
* @param mixed $matches
* @param TFlags $flags
2020-09-05 00:31:50 +02:00
* @param-out (
* TFlags is 1
2020-09-05 00:32:51 +02:00
* ? array<list<string>>
* : (TFlags is 2
* ? list<array<string>>
* : (TFlags is 256|257
* ? array<list<array{string, int}>>
2020-09-05 00:32:51 +02:00
* : (TFlags is 258
* ? list<array<array{string, int}>>
2020-09-05 00:32:51 +02:00
* : (TFlags is 512|513
* ? array<list<?string>>
* : (TFlags is 514
* ? list<array<?string>>
* : (TFlags is 770
* ? list<array<array{?string, int}>>
2020-09-05 00:32:51 +02:00
* : array
* )
* )
* )
* )
* )
* )
2020-09-05 00:31:50 +02:00
* ) $matches
* @return int|false
* @psalm-ignore-falsable-return
*/
2020-10-26 16:53:03 +01:00
function preg_match_all($pattern, $subject, &$matches = [], int $flags = 1, int $offset = 0) {}
2021-11-29 14:21:58 +01:00
/**
* @psalm-pure
* @template TFlags as int-mask<0, 256, 512>
*
* @param string $pattern
* @param string $subject
* @param mixed $matches
* @param TFlags $flags
* @param-out (TFlags is 256 ? array<array-key, array{string, 0|positive-int}|array{'', -1}> :
2021-11-29 14:21:58 +01:00
* TFlags is 512 ? array<array-key, string|null> :
* TFlags is 768 ? array<array-key, array{string, 0|positive-int}|array{null, -1}> :
2021-11-29 14:21:58 +01:00
* array<array-key, string>
* ) $matches
* @return 1|0|false
* @psalm-ignore-falsable-return
*/
function preg_match($pattern, $subject, &$matches = [], int $flags = 0, int $offset = 0) {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* @return (PHP_MAJOR_VERSION is 5|7 ? string|false : string)
2020-05-22 04:47:58 +02:00
* @psalm-ignore-falsable-return
*
* @psalm-flow ($string) -> return
*/
function substr(string $string, int $offset, ?int $length = null) {}
2020-05-22 04:47:58 +02:00
/**
* @psalm-pure
*
* @psalm-flow ($str) -> return
*/
function preg_quote(string $str, ?string $delimiter = null) : string {}
/**
* @psalm-pure
*
2022-12-18 12:13:39 +01:00
* @param string|int|float $values
* @return ($format is non-empty-string
* ? ($values is non-empty-string|int|float ? non-empty-string : string)
* : string)
*
* @psalm-flow ($format, $values) -> return
2020-05-22 04:47:58 +02:00
*/
function sprintf(string $format, ...$values) : string {}
2020-05-23 07:11:16 +02:00
/**
* @psalm-pure
* @return string|false
* @psalm-ignore-falsable-return
2020-11-24 16:44:33 +01:00
*
* @psalm-flow ($format, $values) -> return
*/
function vsprintf(string $format, array $values) {}
/**
* @psalm-pure
* @return string
2020-11-24 16:44:33 +01:00
*
* @psalm-flow ($string) -> return
*/
function wordwrap(string $string, int $width = 75, string $break = "\n", bool $cut_long_words = false) : string {}
/**
* @psalm-pure
*
2020-12-29 12:42:41 +01:00
* @param string|int|float $values
*
* @psalm-taint-specialize
* @psalm-flow ($format, $values) -> return
* @psalm-taint-sink html $format
* @psalm-taint-sink html $values
*/
function printf(string $format, ...$values) : string {}
/**
* @psalm-taint-specialize
* @psalm-taint-sink html $format
* @psalm-taint-sink html $values
*/
function vprintf(string $format, array $values) : int {}
2020-05-23 07:11:16 +02:00
/**
* @psalm-pure
*
* @return string|false
* @psalm-ignore-falsable-return
*
* @psalm-flow ($path) -> return
*/
function realpath(string $path) {}
2020-05-30 22:55:55 +02:00
/**
* @psalm-pure
*
* @param numeric-string $num1
* @param numeric-string $num2
* @return (PHP_MAJOR_VERSION is 8 ? numeric-string : ($num2 is "0" ? null : numeric-string))
2020-05-30 22:55:55 +02:00
*/
function bcdiv(string $num1, string $num2, int $scale = 0): ?string {}
/**
* @psalm-pure
*
* @param scalar|null|object $value
* @return string The string value of var.
*
* @psalm-flow ($value) -> return
*/
function strval ($value): string {}
2020-07-22 05:16:56 +02:00
/**
* @return ($string is non-empty-string ? non-empty-list<string> : non-empty-list<string>|array{null})
2020-07-22 05:16:56 +02:00
* @psalm-pure
*
* @psalm-flow ($string) -> return
2020-07-22 05:16:56 +02:00
*/
function str_getcsv(string $string, string $separator = ',', string $enclosure = '"', string $escape = '\\\\')
2020-07-22 05:16:56 +02:00
{
}
/**
* @template TKey as array-key
* @template TArray as array<mixed, TKey>
*
* @param TArray $array
*
* @return (TArray is non-empty-array ? non-empty-array<TKey, positive-int> : array<TKey, positive-int>)
*
* @psalm-pure
*/
function array_count_values(array $array): array {}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function addcslashes(string $string, string $characters) : string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function addslashes(string $string): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function ucfirst(string $string): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string, $separators) -> return
*/
function ucwords (string $string, string $separators = " \t\r\n\f\v"): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function lcfirst(string $string): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function nl2br(string $string, bool $use_xhtml = false): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function quoted_printable_decode(string $string): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function quoted_printable_encode(string $string): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function quotemeta(string $string): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function chop(string $string, string $characters = " \t\n\r\0\x0B"): string
{
}
/**
* @psalm-pure
* @psalm-flow ($string, $separator) -> return
*/
function chunk_split(string $string, int $length = 76, string $separator= ''): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function convert_uudecode(string $string): string
{
}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function convert_uuencode(string $string) : string
{
}
/**
* @psalm-pure
*
* @psalm-taint-escape ldap
* @psalm-flow ($value) -> return
*/
function ldap_escape(string $value, string $ignore = "", int $flags = 0) : string {}
/**
* @psalm-pure
*
* @return mixed
* @psalm-flow ($json) -> return
*/
function json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0) {}
/**
* @psalm-pure
*
* @return ($flags is 4194304 ? non-empty-string : non-empty-string|false)
*
* @psalm-flow ($value) -> return
* @psalm-ignore-falsable-return
*/
function json_encode(mixed $value, int $flags = 0, int $depth = 512) {}
/**
* @psalm-pure
*
* @return string|false
*
* @psalm-flow ($values) -> return
* @psalm-ignore-falsable-return
*/
function pack(string $format, mixed ...$values) {}
/**
* @psalm-pure
*
* @param string|int $in_codepage
* @param string|int $out_codepage
* @psalm-flow ($subject) -> return
*/
function sapi_windows_cp_conv($in_codepage, $out_codepage, string $subject) : ?string {}
/**
* @psalm-pure
*
* @psalm-flow ($prefix) -> return
*/
function uniqid(string $prefix = "", bool $more_entropy = false) : string {}
/**
* @psalm-pure
*
* @return array|false
* @psalm-ignore-falsable-return
*
* @psalm-flow ($string) -> return
*/
function unpack(string $format, string $string, int $offset = 0) {}
/**
* @psalm-pure
*
* @return string|false
*
* @psalm-flow ($string) -> return
* @psalm-ignore-falsable-return
*/
function base64_decode(string $string, bool $strict = false) {}
/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
* @template T as string
* @param T $string
* @return (T is non-empty-string ? non-empty-string : string)
*/
function base64_encode(string $string) : string {}
/**
* @psalm-pure
*
* @template T as string
* @param T $string
* @return (T is non-empty-string ? non-empty-string : string)
*/
function bin2hex(string $string): string {}
/**
* @psalm-pure
*
* @param resource|null $context
*
* @return ($associative is 0 ? list<string> : array<string, string|list<string>>)|false
*
* @psalm-taint-sink ssrf $url
*/
function get_headers(string $url, int $associative = 0, $context = null) : array|false {}
/**
* @psalm-pure
*
* @return array<lowercase-string, string>|false
*
* @psalm-taint-sink ssrf $filename
*/
function get_meta_tags(string $filename, bool $use_include_path = false) : array|false {}
/**
2021-07-15 23:47:00 +02:00
* @return ($categorize is false ? array<string,int|string|float|bool|null|array|resource> : array<string, array<string,int|string|float|bool|null|array|resource>>)
*/
2021-07-15 23:47:00 +02:00
function get_defined_constants(bool $categorize = false): array {}
2021-10-12 20:13:04 +02:00
/**
2021-10-13 10:33:26 +02:00
* @param mixed $object_or_class
* @param class-string $class
2022-05-12 15:37:29 +02:00
* @param bool $allow_string
* @return ($allow_string is false ? ($object_or_class is object ? bool : false) : bool)
2021-10-12 20:13:04 +02:00
*/
2021-11-13 22:13:55 +01:00
function is_a($object_or_class, string $class, $allow_string = false): bool{}
/**
* @template T of array|string
* @param T $string
* @return (T is array<int, string> ? array<int, string> : T is array ? array : string|false)
* @psalm-ignore-falsable-return
2021-11-13 22:13:55 +01:00
*/
function mb_convert_encoding(array|string $string, string $to_encoding, array|string|null $from_encoding = null): array|string|false{}
/**
* @template TRead of null|array<array-key, resource>
* @template TWrite of null|array<array-key, resource>
* @template TExcept of null|array<array-key, resource>
* @param TRead $read
* @param TWrite $write
* @param TExcept $except
* @return false|int<0, max>
* @param-out (TRead is null ? null : array<array-key, resource>) $read
* @param-out (TWrite is null ? null : array<array-key, resource>) $write
* @param-out (TExcept is null ? null : array<array-key, resource>) $except
* @psalm-suppress ReferenceConstraintViolation
*/
function stream_select(null|array &$read, null|array &$write, null|array &$except, null|int $seconds, null|int $microseconds = null) : bool|int {}
/**
* @psalm-pure
*
* @psalm-taint-escape sql
* @psalm-flow ($string) -> return
*/
function mysqli_escape_string($string) {}
/**
* @psalm-pure
*
* @psalm-taint-escape sql
* @psalm-flow ($string) -> return
*/
function mysqli_real_escape_string($string) {}
/**
* @psalm-pure
*
* @psalm-taint-escape sql
* @psalm-flow ($string) -> return
*/
function db2_escape_string($string) {}
/**
* @psalm-pure
*
* @psalm-taint-escape sql
* @psalm-flow ($string) -> return
*/
function cubrid_real_escape_string($string) {}
/**
* @psalm-pure
*
* @psalm-taint-escape sql
* @psalm-flow ($string1, $string2) -> return
*/
function pg_escape_bytea($string1, $string2 = null) {}
/**
* @psalm-pure
*
* @psalm-taint-escape sql
* @psalm-flow ($string1, $string2) -> return
*/
function pg_escape_identifier($string1, $string2 = null) {}
/**
* @psalm-pure
*
* @psalm-taint-escape sql
* @psalm-flow ($string1, $string2) -> return
*/
function pg_escape_literal($string1, $string2 = null) {}
/**
* @psalm-pure
*
* @psalm-taint-escape sql
* @psalm-flow ($string1, $string2) -> return
*/
function pg_escape_string($string1, $string2 = null) {}