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 = null, ?array $env_vars = null, ?array $options = null) {}
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'], // 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'], []);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -918,4 +918,11 @@ public function testBug2888(): void
]);
}

public function testBug11777(): void
{
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-11777.php'], []);
}

}
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-11777.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Bug11777;

class HelloWorld {
/** @var array<int, resource> */
private array $pipes;

public function sayHello(string $cmd): void {
proc_open($cmd, [0 => ['pipe', 'r']], $this->pipes);
}
}
Loading