Skip to content

Commit 68ab665

Browse files
committed
Fix passthru() on PHP 8.1
1 parent b7ffc8d commit 68ab665

7 files changed

Lines changed: 31 additions & 116 deletions

File tree

generated/8.1/functionsList.php

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/8.1/rector-migrate.php

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/8.2/exec.php

Lines changed: 0 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/8.3/exec.php

Lines changed: 0 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/8.4/exec.php

Lines changed: 0 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/8.5/exec.php

Lines changed: 0 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/special_cases.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Safe\Exceptions\PcreException;
1818
use Safe\Exceptions\SimplexmlException;
1919
use Safe\Exceptions\FilesystemException;
20+
use Safe\Exceptions\ExecException;
2021

2122
use const PREG_NO_ERROR;
2223

@@ -399,3 +400,31 @@ function fgetcsv($stream, ?int $length = null, string $separator = ",", string $
399400
}
400401
return $safeResult;
401402
}
403+
404+
/**
405+
* The passthru function is similar to the
406+
* exec function in that it executes a
407+
* command. This function
408+
* should be used in place of exec or
409+
* system when the output from the Unix command
410+
* is binary data which needs to be passed directly back to the
411+
* browser. A common use for this is to execute something like the
412+
* pbmplus utilities that can output an image stream directly. By
413+
* setting the Content-type to image/gif and
414+
* then calling a pbmplus program to output a gif, you can create
415+
* PHP scripts that output images directly.
416+
*
417+
* @param string $command The command that will be executed.
418+
* @param int|null $result_code If the result_code argument is present, the
419+
* return status of the Unix command will be placed here.
420+
* @throws ExecException
421+
*
422+
*/
423+
function passthru(string $command, ?int &$result_code = null): void
424+
{
425+
error_clear_last();
426+
$safeResult = \passthru($command, $result_code);
427+
if ($safeResult === false) {
428+
throw ExecException::createFromPhpError();
429+
}
430+
}

0 commit comments

Comments
 (0)