From 06079e8f47c410484948b59d49770771916540e7 Mon Sep 17 00:00:00 2001 From: Silas Joisten Date: Wed, 14 May 2025 18:39:44 +0200 Subject: [PATCH 1/5] fix: `passthru` --- generated/8.1/functionsList.php | 1 + generated/8.1/rector-migrate.php | 1 + generated/8.2/exec.php | 29 -------------------------- generated/8.3/exec.php | 29 -------------------------- generated/8.4/exec.php | 29 -------------------------- generated/8.5/exec.php | 29 -------------------------- lib/special_cases.php | 35 ++++++++++++++++++++++++++++++++ 7 files changed, 37 insertions(+), 116 deletions(-) diff --git a/generated/8.1/functionsList.php b/generated/8.1/functionsList.php index b3b3f39e..c170d754 100644 --- a/generated/8.1/functionsList.php +++ b/generated/8.1/functionsList.php @@ -684,6 +684,7 @@ 'parse_ini_file', 'parse_ini_string', 'parse_url', + 'passthru', 'pclose', 'pcntl_getpriority', 'pcntl_setpriority', diff --git a/generated/8.1/rector-migrate.php b/generated/8.1/rector-migrate.php index 334aa51e..f74d9bc4 100644 --- a/generated/8.1/rector-migrate.php +++ b/generated/8.1/rector-migrate.php @@ -692,6 +692,7 @@ 'parse_ini_file' => 'Safe\parse_ini_file', 'parse_ini_string' => 'Safe\parse_ini_string', 'parse_url' => 'Safe\parse_url', + 'passthru' => 'Safe\passthru', 'pclose' => 'Safe\pclose', 'pcntl_getpriority' => 'Safe\pcntl_getpriority', 'pcntl_setpriority' => 'Safe\pcntl_setpriority', diff --git a/generated/8.2/exec.php b/generated/8.2/exec.php index 7cbb1bce..7e35d71b 100644 --- a/generated/8.2/exec.php +++ b/generated/8.2/exec.php @@ -43,35 +43,6 @@ function exec(string $command, ?array &$output = null, ?int &$result_code = null } -/** - * The passthru function is similar to the - * exec function in that it executes a - * command. This function - * should be used in place of exec or - * system when the output from the Unix command - * is binary data which needs to be passed directly back to the - * browser. A common use for this is to execute something like the - * pbmplus utilities that can output an image stream directly. By - * setting the Content-type to image/gif and - * then calling a pbmplus program to output a gif, you can create - * PHP scripts that output images directly. - * - * @param string $command The command that will be executed. - * @param int|null $result_code If the result_code argument is present, the - * return status of the Unix command will be placed here. - * @throws ExecException - * - */ -function passthru(string $command, ?int &$result_code = null): void -{ - error_clear_last(); - $safeResult = \passthru($command, $result_code); - if ($safeResult === false) { - throw ExecException::createFromPhpError(); - } -} - - /** * proc_close is similar to pclose * except that it only works on processes opened by diff --git a/generated/8.3/exec.php b/generated/8.3/exec.php index 7cbb1bce..7e35d71b 100644 --- a/generated/8.3/exec.php +++ b/generated/8.3/exec.php @@ -43,35 +43,6 @@ function exec(string $command, ?array &$output = null, ?int &$result_code = null } -/** - * The passthru function is similar to the - * exec function in that it executes a - * command. This function - * should be used in place of exec or - * system when the output from the Unix command - * is binary data which needs to be passed directly back to the - * browser. A common use for this is to execute something like the - * pbmplus utilities that can output an image stream directly. By - * setting the Content-type to image/gif and - * then calling a pbmplus program to output a gif, you can create - * PHP scripts that output images directly. - * - * @param string $command The command that will be executed. - * @param int|null $result_code If the result_code argument is present, the - * return status of the Unix command will be placed here. - * @throws ExecException - * - */ -function passthru(string $command, ?int &$result_code = null): void -{ - error_clear_last(); - $safeResult = \passthru($command, $result_code); - if ($safeResult === false) { - throw ExecException::createFromPhpError(); - } -} - - /** * proc_close is similar to pclose * except that it only works on processes opened by diff --git a/generated/8.4/exec.php b/generated/8.4/exec.php index 7cbb1bce..7e35d71b 100644 --- a/generated/8.4/exec.php +++ b/generated/8.4/exec.php @@ -43,35 +43,6 @@ function exec(string $command, ?array &$output = null, ?int &$result_code = null } -/** - * The passthru function is similar to the - * exec function in that it executes a - * command. This function - * should be used in place of exec or - * system when the output from the Unix command - * is binary data which needs to be passed directly back to the - * browser. A common use for this is to execute something like the - * pbmplus utilities that can output an image stream directly. By - * setting the Content-type to image/gif and - * then calling a pbmplus program to output a gif, you can create - * PHP scripts that output images directly. - * - * @param string $command The command that will be executed. - * @param int|null $result_code If the result_code argument is present, the - * return status of the Unix command will be placed here. - * @throws ExecException - * - */ -function passthru(string $command, ?int &$result_code = null): void -{ - error_clear_last(); - $safeResult = \passthru($command, $result_code); - if ($safeResult === false) { - throw ExecException::createFromPhpError(); - } -} - - /** * proc_close is similar to pclose * except that it only works on processes opened by diff --git a/generated/8.5/exec.php b/generated/8.5/exec.php index 7cbb1bce..7e35d71b 100644 --- a/generated/8.5/exec.php +++ b/generated/8.5/exec.php @@ -43,35 +43,6 @@ function exec(string $command, ?array &$output = null, ?int &$result_code = null } -/** - * The passthru function is similar to the - * exec function in that it executes a - * command. This function - * should be used in place of exec or - * system when the output from the Unix command - * is binary data which needs to be passed directly back to the - * browser. A common use for this is to execute something like the - * pbmplus utilities that can output an image stream directly. By - * setting the Content-type to image/gif and - * then calling a pbmplus program to output a gif, you can create - * PHP scripts that output images directly. - * - * @param string $command The command that will be executed. - * @param int|null $result_code If the result_code argument is present, the - * return status of the Unix command will be placed here. - * @throws ExecException - * - */ -function passthru(string $command, ?int &$result_code = null): void -{ - error_clear_last(); - $safeResult = \passthru($command, $result_code); - if ($safeResult === false) { - throw ExecException::createFromPhpError(); - } -} - - /** * proc_close is similar to pclose * except that it only works on processes opened by diff --git a/lib/special_cases.php b/lib/special_cases.php index a324166d..98d4e895 100644 --- a/lib/special_cases.php +++ b/lib/special_cases.php @@ -8,6 +8,7 @@ namespace Safe; +use Safe\Exceptions\ExecException; use Safe\Exceptions\MiscException; use Safe\Exceptions\PosixException; use Safe\Exceptions\SocketsException; @@ -399,3 +400,37 @@ function fgetcsv($stream, ?int $length = null, string $separator = ",", string $ } return $safeResult; } + +/** + * The passthru function is similar to the + * exec function in that it executes a + * command. This function + * should be used in place of exec or + * system when the output from the Unix command + * is binary data which needs to be passed directly back to the + * browser. A common use for this is to execute something like the + * pbmplus utilities that can output an image stream directly. By + * setting the Content-type to image/gif and + * then calling a pbmplus program to output a gif, you can create + * PHP scripts that output images directly. + * + * @param string $command The command that will be executed. + * @param int|null $result_code If the result_code argument is present, the + * return status of the Unix command will be placed here. + * @throws ExecException + * + */ +function passthru(string $command, ?int &$result_code = null): void +{ + error_clear_last(); + + if (null === $result_code) { + $safeResult = \passthru($command); + } else { + $safeResult = \passthru($command, $result_code); + } + + if ($safeResult === false) { + throw ExecException::createFromPhpError(); + } +} \ No newline at end of file From 1aedb3152aad115d8f0b28491f573cfcd81679c0 Mon Sep 17 00:00:00 2001 From: Silas Joisten Date: Wed, 14 May 2025 18:41:26 +0200 Subject: [PATCH 2/5] Fix --- lib/special_cases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/special_cases.php b/lib/special_cases.php index 98d4e895..13304df1 100644 --- a/lib/special_cases.php +++ b/lib/special_cases.php @@ -433,4 +433,4 @@ function passthru(string $command, ?int &$result_code = null): void if ($safeResult === false) { throw ExecException::createFromPhpError(); } -} \ No newline at end of file +} From 79670cbb0b41d681d24d6a2ee3152d29a7b99d8c Mon Sep 17 00:00:00 2001 From: Silas Joisten Date: Thu, 15 May 2025 07:34:11 +0200 Subject: [PATCH 3/5] Fix --- lib/special_cases.php | 7 +------ phpstan.neon | 7 ++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/special_cases.php b/lib/special_cases.php index 13304df1..3b191ffe 100644 --- a/lib/special_cases.php +++ b/lib/special_cases.php @@ -424,12 +424,7 @@ function passthru(string $command, ?int &$result_code = null): void { error_clear_last(); - if (null === $result_code) { - $safeResult = \passthru($command); - } else { - $safeResult = \passthru($command, $result_code); - } - + $safeResult = \passthru($command, $result_code); if ($safeResult === false) { throw ExecException::createFromPhpError(); } diff --git a/phpstan.neon b/phpstan.neon index 17f91adc..13cf9db0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,4 +11,9 @@ parameters: # The level 9 is the highest level (with check for mixed type) level: 8 ignoreErrors: - # A lot of functions are in extensions so it is ok not to find those + # This must be ignored because there is no way of fixing it. + - + message: '#^Function Safe\\passthru\(\) never assigns null to &\$result_code so it can be removed from the by\-ref type\.$#' + identifier: parameterByRef.unusedType + count: 1 + path: lib/special_cases.php \ No newline at end of file From bc0655d91df582909cd7e9a9dbc371108cfe00f8 Mon Sep 17 00:00:00 2001 From: Silas Joisten Date: Thu, 15 May 2025 07:35:31 +0200 Subject: [PATCH 4/5] Fix --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 13cf9db0..789cba64 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -16,4 +16,4 @@ parameters: message: '#^Function Safe\\passthru\(\) never assigns null to &\$result_code so it can be removed from the by\-ref type\.$#' identifier: parameterByRef.unusedType count: 1 - path: lib/special_cases.php \ No newline at end of file + path: lib/special_cases.php From e6aef9ee8527cd973480d470c89d8a93d4fa51d2 Mon Sep 17 00:00:00 2001 From: Silas Joisten Date: Thu, 15 May 2025 07:36:56 +0200 Subject: [PATCH 5/5] Fix --- phpstan.neon | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 789cba64..9e1921ad 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -12,8 +12,8 @@ parameters: level: 8 ignoreErrors: # This must be ignored because there is no way of fixing it. - - - message: '#^Function Safe\\passthru\(\) never assigns null to &\$result_code so it can be removed from the by\-ref type\.$#' - identifier: parameterByRef.unusedType - count: 1 - path: lib/special_cases.php + - + message: '#^Function Safe\\passthru\(\) never assigns null to &\$result_code so it can be removed from the by\-ref type\.$#' + identifier: parameterByRef.unusedType + count: 1 + path: lib/special_cases.php