Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions stubs/core.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $command
* @param array<P, list<string>|resource> $descriptor_spec
* @param mixed $pipes
* @param null|array<string, mixed> $env_vars
* @param null|array<string, bool> $options
*
* @param-out array<P, resource> $pipes
*
* @return resource|false
*/
function proc_open($command, array $descriptor_spec, &$pipes, ?string $cwd, ?array $env_vars, ?array $options) {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {}

not sure if needed in stubs

42 changes: 42 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-13197.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php declare(strict_types = 1);

namespace Bug13197;

use function PHPStan\Testing\assertType;

/**
* @return array{string, string}|null STDOUT & STDERR tuple
*/
function execute(string $command): ?array
{
if (!function_exists('proc_open')) {
return null;
}

$pipes = [];

$process = @proc_open(
$command,
[
['pipe', 'rb'],
['pipe', 'wb'], // stdout
['pipe', 'wb'], // stderr
],
$pipes
);

assertType('array<0|1|2, resource>', $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];
}
26 changes: 26 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-13197b.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types = 1);

namespace Bug13197b;

use function PHPStan\Testing\assertType;

function execute(string $command): void
{
if (!function_exists('proc_open')) {
return;
}

$pipes = [];

$process = @proc_open(
$command,
[
['pipe', 'rb'],
3 => ['pipe', 'wb'], // stdout
5 => ['pipe', 'wb'], // stderr
Comment on lines +19 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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'],

small comment improvement, stdout is more or less always 1 pipe index

],
$pipes
);

assertType('array<0|3|5, resource>', $pipes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2216,4 +2216,11 @@ public function testBug12317(): void
]);
}

public function testBug13197(): void
{
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-13197.php'], []);
}

}
Loading