From a62c643329f0032a07812cf710a34a420891c098 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 11:04:13 +0200 Subject: [PATCH 01/11] 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 2fd2fc0506..e9a48467d9 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 21cdbe660ca771a9a1c3c6ace815fd0157355551 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 11:18:26 +0200 Subject: [PATCH 02/11] fix types --- stubs/core.stub | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stubs/core.stub b/stubs/core.stub index e9a48467d9..56dc3f9663 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 d3be756aa81a9696aea767e15dd9a44a3c14a461 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 11:27:26 +0200 Subject: [PATCH 03/11] iterable types --- stubs/core.stub | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/core.stub b/stubs/core.stub index 56dc3f9663..2472c227e9 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 aaa46da9a0b81829211c5f3ef822a981efa540e0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 26 Aug 2025 11:32:24 +0200 Subject: [PATCH 04/11] 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 2472c227e9..e540587ad5 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 33c44985229b52441807f5f6bd1ac858113768ad Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 27 Aug 2025 09:09:36 +0200 Subject: [PATCH 05/11] 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 e540587ad5..81183f8ae5 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 6ac49865c38afe89a0b1c1b41ee317d93852cd8c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 30 Aug 2025 10:42:32 +0200 Subject: [PATCH 06/11] 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 9a9cc2f6e5..457927c97c 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -2317,4 +2317,11 @@ public function testBug12317(): void ]); } + public function testBug13197(): void + { + $this->checkExplicitMixed = true; + $this->checkImplicitMixed = true; + $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-13197.php'], []); + } + } From 73ed9763bb6bab58199d71255fb1522f4542965d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 30 Aug 2025 12:43:34 +0200 Subject: [PATCH 07/11] 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 81183f8ae5..75e2106cb2 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 3b1345ad9a42d7c6835f2579cf7d344a287636cc Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 30 Aug 2025 12:46:31 +0200 Subject: [PATCH 08/11] simplify --- stubs/core.stub | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/core.stub b/stubs/core.stub index 75e2106cb2..6d5b36b08d 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 952873ecbee7bfaa86cedf97d52c527ded5b48ea Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Sep 2025 16:17:47 +0200 Subject: [PATCH 09/11] 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 6d5b36b08d..f608f51110 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 1d1d4e1b9c4d7514c8aa7ddd39741a2c5d0b058d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Sep 2025 16:18:05 +0200 Subject: [PATCH 10/11] 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 ); From b64cec6386855c9ce7e879c9275f7c093fc93bdb Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 12 Sep 2025 16:38:46 +0200 Subject: [PATCH 11/11] added regression test --- .../Properties/TypesAssignedToPropertiesRuleTest.php | 7 +++++++ tests/PHPStan/Rules/Properties/data/bug-11777.php | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/PHPStan/Rules/Properties/data/bug-11777.php diff --git a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php index 5a83b43a6c..300a8a9858 100644 --- a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php @@ -928,4 +928,11 @@ public function testBug11241b(): void ]); } + public function testBug11777(): void + { + $this->checkExplicitMixed = true; + $this->checkImplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-11777.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Properties/data/bug-11777.php b/tests/PHPStan/Rules/Properties/data/bug-11777.php new file mode 100644 index 0000000000..3bc1774ee4 --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/bug-11777.php @@ -0,0 +1,12 @@ + */ + private array $pipes; + + public function sayHello(string $cmd): void { + proc_open($cmd, [0 => ['pipe', 'r']], $this->pipes); + } +}