Skip to content

Commit c40d0f2

Browse files
fix: passthru on PHP 8.1 (#691)
Co-authored-by: Oskar Stark <[email protected]>
1 parent 2fe3bd5 commit c40d0f2

File tree

8 files changed

+38
-117
lines changed

8 files changed

+38
-117
lines changed

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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Safe;
1010

11+
use Safe\Exceptions\ExecException;
1112
use Safe\Exceptions\MiscException;
1213
use Safe\Exceptions\PosixException;
1314
use Safe\Exceptions\SocketsException;
@@ -399,3 +400,32 @@ 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+
427+
$safeResult = \passthru($command, $result_code);
428+
if ($safeResult === false) {
429+
throw ExecException::createFromPhpError();
430+
}
431+
}

phpstan.neon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ parameters:
1111
# The level 9 is the highest level (with check for mixed type)
1212
level: 8
1313
ignoreErrors:
14-
# A lot of functions are in extensions so it is ok not to find those
14+
# This must be ignored because there is no way of fixing it.
15+
-
16+
message: '#^Function Safe\\passthru\(\) never assigns null to &\$result_code so it can be removed from the by\-ref type\.$#'
17+
identifier: parameterByRef.unusedType
18+
count: 1
19+
path: lib/special_cases.php

0 commit comments

Comments
 (0)