diff --git a/stubs/core.stub b/stubs/core.stub index 6456c2d1b9..bbf9c9bd5c 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -362,3 +362,18 @@ function header_register_callback(callable $callback): bool {} * @param-later-invoked-callable $callback */ function register_tick_function(callable $callback, mixed ...$args): bool {} + +/** + * @template P of int + * + * @param string|list $command + * @param array|resource> $descriptor_spec + * @param mixed $pipes + * @param null|array $env_vars + * @param null|array $options + * + * @param-out array $pipes + * + * @return resource|false + */ +function proc_open($command, array $descriptor_spec, &$pipes, ?string $cwd = null, ?array $env_vars = null, ?array $options = null) {} diff --git a/tests/PHPStan/Analyser/nsrt/bug-13197.php b/tests/PHPStan/Analyser/nsrt/bug-13197.php new file mode 100644 index 0000000000..c16af1da1c --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-13197.php @@ -0,0 +1,42 @@ +', $pipes); + + if (!is_resource($process)) { + return null; + } + + fclose($pipes[0]); + + $stdout = (string) stream_get_contents($pipes[1]); + $stderr = (string) stream_get_contents($pipes[2]); + + proc_close($process); + + return [$stdout, $stderr]; +} diff --git a/tests/PHPStan/Analyser/nsrt/bug-13197b.php b/tests/PHPStan/Analyser/nsrt/bug-13197b.php new file mode 100644 index 0000000000..9067928453 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-13197b.php @@ -0,0 +1,26 @@ + ['pipe', 'wb'], // https://stackoverflow.com/questions/28909347/is-it-possible-to-connect-more-than-the-two-standard-streams-to-a-terminal-in-li#28909376 + 5 => ['pipe', 'wb'], + ], + $pipes + ); + + assertType('array<0|3|5, resource>', $pipes); +} diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 7ff0f86645..356ce61dad 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -2241,4 +2241,11 @@ public function testBug12317(): void ]); } + public function testBug13197(): void + { + $this->checkExplicitMixed = true; + $this->checkImplicitMixed = true; + $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-13197.php'], []); + } + }