From fe4fb782ee0c9cae35fa5a05ed4b98451459415e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 11:04:13 +0200 Subject: [PATCH 01/10] Added proc_open() stub for param-out --- stubs/core.stub | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stubs/core.stub b/stubs/core.stub index 6456c2d1b9..f2490155bc 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -362,3 +362,8 @@ function header_register_callback(callable $callback): bool {} * @param-later-invoked-callable $callback */ function register_tick_function(callable $callback, mixed ...$args): bool {} + +/** + * @param-out array $pipes + */ +function proc_open(array|string $command, array $descriptor_spec, &$pipes, ?string $cwd, ?array $env_vars, ?array $options): resource|false {} From 91d44fa92ec470d1e88fbce928e8e1dd150c3e59 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 11:18:26 +0200 Subject: [PATCH 02/10] fix types --- stubs/core.stub | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stubs/core.stub b/stubs/core.stub index f2490155bc..8c23e21084 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -364,6 +364,14 @@ function header_register_callback(callable $callback): bool {} function register_tick_function(callable $callback, mixed ...$args): bool {} /** - * @param-out array $pipes + * @param string|array $command + * @param array $descriptor_spec + * @param array $pipes + * @param array $env_vars + * @param array $options + * + * @param-out list $pipes + * + * @return resource|false */ -function proc_open(array|string $command, array $descriptor_spec, &$pipes, ?string $cwd, ?array $env_vars, ?array $options): resource|false {} +function proc_open(array|string $command, array $descriptor_spec, &$pipes, ?string $cwd, ?array $env_vars, ?array $options) {} From 1345cb756a2d2810e4d1905e7476940e4ad46f15 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 11:27:26 +0200 Subject: [PATCH 03/10] iterable types --- stubs/core.stub | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/core.stub b/stubs/core.stub index 8c23e21084..624734a105 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -365,10 +365,10 @@ function register_tick_function(callable $callback, mixed ...$args): bool {} /** * @param string|array $command - * @param array $descriptor_spec - * @param array $pipes + * @param list|resource> $descriptor_spec + * @param list $pipes * @param array $env_vars - * @param array $options + * @param array $options * * @param-out list $pipes * From f35df679528218459d5164a1030079d5a7ccdea4 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 11:32:24 +0200 Subject: [PATCH 04/10] fix php 7.4 --- stubs/core.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/core.stub b/stubs/core.stub index 624734a105..0b65c11827 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -374,4 +374,4 @@ function register_tick_function(callable $callback, mixed ...$args): bool {} * * @return resource|false */ -function proc_open(array|string $command, array $descriptor_spec, &$pipes, ?string $cwd, ?array $env_vars, ?array $options) {} +function proc_open($command, array $descriptor_spec, &$pipes, ?string $cwd, ?array $env_vars, ?array $options) {} From a3b456b249186f16e6aa2da982df970ecd78566e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 27 Aug 2025 09:09:36 +0200 Subject: [PATCH 05/10] Update core.stub --- stubs/core.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/core.stub b/stubs/core.stub index 0b65c11827..517801fa05 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -366,7 +366,7 @@ function register_tick_function(callable $callback, mixed ...$args): bool {} /** * @param string|array $command * @param list|resource> $descriptor_spec - * @param list $pipes + * @param array $pipes * @param array $env_vars * @param array $options * From 43496433570de43a0a6d59a884e6dd97bfea01e5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 30 Aug 2025 10:42:32 +0200 Subject: [PATCH 06/10] regression test --- tests/PHPStan/Analyser/nsrt/bug-13197.php | 42 +++++++++++++++++++ .../CallToFunctionParametersRuleTest.php | 7 ++++ 2 files changed, 49 insertions(+) create mode 100644 tests/PHPStan/Analyser/nsrt/bug-13197.php diff --git a/tests/PHPStan/Analyser/nsrt/bug-13197.php b/tests/PHPStan/Analyser/nsrt/bug-13197.php new file mode 100644 index 0000000000..affc07edaf --- /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/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'], []); + } + } From 4887e09d12922cafbf779f5ccb6256617dc48549 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 30 Aug 2025 12:43:34 +0200 Subject: [PATCH 07/10] more precise types --- stubs/core.stub | 12 +++++----- tests/PHPStan/Analyser/nsrt/bug-13197.php | 2 +- tests/PHPStan/Analyser/nsrt/bug-13197b.php | 26 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 tests/PHPStan/Analyser/nsrt/bug-13197b.php diff --git a/stubs/core.stub b/stubs/core.stub index 517801fa05..e15336db53 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -364,13 +364,15 @@ function header_register_callback(callable $callback): bool {} function register_tick_function(callable $callback, mixed ...$args): bool {} /** - * @param string|array $command - * @param list|resource> $descriptor_spec - * @param array $pipes - * @param array $env_vars + * @template P of int = int + * + * @param string|list $command + * @param array|resource> $descriptor_spec + * @param array $pipes + * @param array $env_vars * @param array $options * - * @param-out list $pipes + * @param-out array $pipes * * @return resource|false */ diff --git a/tests/PHPStan/Analyser/nsrt/bug-13197.php b/tests/PHPStan/Analyser/nsrt/bug-13197.php index affc07edaf..c16af1da1c 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-13197.php +++ b/tests/PHPStan/Analyser/nsrt/bug-13197.php @@ -25,7 +25,7 @@ function execute(string $command): ?array $pipes ); - assertType('list', $pipes); + assertType('array<0|1|2, resource>', $pipes); if (!is_resource($process)) { return null; diff --git a/tests/PHPStan/Analyser/nsrt/bug-13197b.php b/tests/PHPStan/Analyser/nsrt/bug-13197b.php new file mode 100644 index 0000000000..a4fed4ff7d --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-13197b.php @@ -0,0 +1,26 @@ + ['pipe', 'wb'], // stdout + 5 => ['pipe', 'wb'], // stderr + ], + $pipes + ); + + assertType('array<0|3|5, resource>', $pipes); +} From 7cb6624599896be0477808e0135ace69814a600f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 30 Aug 2025 12:46:31 +0200 Subject: [PATCH 08/10] simplify --- stubs/core.stub | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/core.stub b/stubs/core.stub index e15336db53..5e2769b6c1 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -364,13 +364,13 @@ function header_register_callback(callable $callback): bool {} function register_tick_function(callable $callback, mixed ...$args): bool {} /** - * @template P of int = int + * @template P of int * * @param string|list $command * @param array|resource> $descriptor_spec - * @param array $pipes - * @param array $env_vars - * @param array $options + * @param mixed $pipes + * @param null|array $env_vars + * @param null|array $options * * @param-out array $pipes * From ab548bbf0c14b8111aa26a75f8d7fd8fac301d66 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Sep 2025 16:17:47 +0200 Subject: [PATCH 09/10] defaults MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Voříšek --- stubs/core.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/core.stub b/stubs/core.stub index 5e2769b6c1..bbf9c9bd5c 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -376,4 +376,4 @@ function register_tick_function(callable $callback, mixed ...$args): bool {} * * @return resource|false */ -function proc_open($command, array $descriptor_spec, &$pipes, ?string $cwd, ?array $env_vars, ?array $options) {} +function proc_open($command, array $descriptor_spec, &$pipes, ?string $cwd = null, ?array $env_vars = null, ?array $options = null) {} From 6ec8263d55a72313c71bb5c648b173e369fe17f1 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Sep 2025 16:18:05 +0200 Subject: [PATCH 10/10] comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Voříšek --- tests/PHPStan/Analyser/nsrt/bug-13197b.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PHPStan/Analyser/nsrt/bug-13197b.php b/tests/PHPStan/Analyser/nsrt/bug-13197b.php index a4fed4ff7d..9067928453 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-13197b.php +++ b/tests/PHPStan/Analyser/nsrt/bug-13197b.php @@ -16,8 +16,8 @@ function execute(string $command): void $command, [ ['pipe', 'rb'], - 3 => ['pipe', 'wb'], // stdout - 5 => ['pipe', 'wb'], // stderr + 3 => ['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 );