diff --git a/src/Composer/Installer/BinaryInstaller.php b/src/Composer/Installer/BinaryInstaller.php index 19a48eada..14331c597 100644 --- a/src/Composer/Installer/BinaryInstaller.php +++ b/src/Composer/Installer/BinaryInstaller.php @@ -271,21 +271,27 @@ class BinaryInstaller /** * Proxy PHP file generated by Composer * - * This file includes the referenced bin path ($binPath) using eval to remove the shebang if present + * This file includes the referenced bin path ($binPath) using ob_start to remove the shebang if present + * to prevent the shebang from being output on PHP<8 * * @generated */ \$binPath = realpath(__DIR__ . "/" . $binPathExported); + +if (PHP_VERSION_ID >= 80000) { + include \$binPath; + exit(0); +} + \$contents = file_get_contents(\$binPath); \$contents = preg_replace('{^#!/.+\\r?\\n<\\?(php)?}', '', \$contents, 1, \$replaced); if (\$replaced) { - \$contents = strtr(\$contents, array( - '__FILE__' => var_export(\$binPath, true), - '__DIR__' => var_export(dirname(\$binPath), true), - )); + ob_start(function (\$buffer, \$phase) { + return (PHP_OUTPUT_HANDLER_START & \$phase) && '#!' === substr(\$buffer, 0, 2) ? '' : \$buffer; + }, 1); - eval(\$contents); + include \$binPath; exit(0); } include \$binPath;