Skip to content

Commit

Permalink
minor symfony#58188 Don't use is_resource() on non-streams (nicolas-g…
Browse files Browse the repository at this point in the history
…rekas)

This PR was merged into the 5.4 branch.

Discussion
----------

Don't use is_resource() on non-streams

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Prepares for https://wiki.php.net/rfc/resource_to_object_conversion

Commits
-------

b12b7a0 Don't use is_resource() on non-streams
  • Loading branch information
fabpot committed Sep 6, 2024
2 parents 73ca0b7 + b12b7a0 commit d7000e6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/Symfony/Component/Console/Terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ private static function readFromProcess(string $command): ?string

$cp = \function_exists('sapi_windows_cp_set') ? sapi_windows_cp_get() : 0;

$process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]);
if (!\is_resource($process)) {
if (!$process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true])) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct(?string $minLevel = null, $output = null, ?callable

$this->minLevelIndex = self::LEVELS[$minLevel];
$this->formatter = $formatter ?: [$this, 'format'];
if ($output && false === $this->handle = \is_resource($output) ? $output : @fopen($output, 'a')) {
if ($output && false === $this->handle = \is_string($output) ? @fopen($output, 'a') : $output) {
throw new InvalidArgumentException(sprintf('Unable to open "%s".', $output));
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public function start(?callable $callback = null, array $env = [])

$this->process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);

if (!\is_resource($this->process)) {
if (!$this->process) {
throw new RuntimeException('Unable to launch a new process.');
}
$this->status = self::STATUS_STARTED;
Expand Down Expand Up @@ -1456,8 +1456,9 @@ private function readPipes(bool $blocking, bool $close)
private function close(): int
{
$this->processPipes->close();
if (\is_resource($this->process)) {
if ($this->process) {
proc_close($this->process);
$this->process = null;
}
$this->exitcode = $this->processInformation['exitcode'];
$this->status = self::STATUS_TERMINATED;
Expand Down

0 comments on commit d7000e6

Please sign in to comment.