Skip to content

Commit 032f61d

Browse files
committed
Workaround for stub generation for prior versions of PHP with exit() and die()
1 parent 6f14fcc commit 032f61d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

build/gen_stub.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,15 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly =
8383
}
8484
}
8585

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

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

0 commit comments

Comments
 (0)