Skip to content

Commit

Permalink
Workaround for stub generation for prior versions of PHP with exit() …
Browse files Browse the repository at this point in the history
…and die()
  • Loading branch information
Girgias committed Aug 13, 2024
1 parent f886231 commit 168bb84
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly =
}
}

/* As exit() and die() used to be proper token/keywords we need to hack-around for versions prior to PHP 8.4 */
$hasSpecialExitAsFunctionHandling = PHP_VERSION_ID < 804000 && str_ends_with($stubFile, 'zend_builtin_functions.stub.php');
if (!$fileInfo = $context->parsedFiles[$stubFile] ?? null) {
initPhpParser();
$fileInfo = parseStubFile($stubCode ?? file_get_contents($stubFile));
$stubContent = $stubCode ?? file_get_contents($stubFile);
if ($hasSpecialExitAsFunctionHandling) {
$stubContent = str_replace(['exit', 'die'], ['exit_dummy', 'die_dummy'], $stubContent);
}
$fileInfo = parseStubFile($stubContent);
$context->parsedFiles[$stubFile] = $fileInfo;

foreach ($fileInfo->dependencies as $dependency) {
Expand Down Expand Up @@ -118,6 +124,9 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly =
$context->allConstInfos,
$stubHash
);
if ($hasSpecialExitAsFunctionHandling) {
$arginfoCode = str_replace(['exit_dummy', 'die_dummy'], ['exit', 'die'], $arginfoCode);
}
if (($context->forceRegeneration || $stubHash !== $oldStubHash) && file_put_contents($arginfoFile, $arginfoCode)) {
echo "Saved $arginfoFile\n";
}
Expand Down

0 comments on commit 168bb84

Please sign in to comment.