1
0
mirror of https://github.com/php/php-src.git synced 2026-04-22 23:48:14 +02:00

Add gen_stub --legacy flag

This flag generates an arginfo file that discards all type and
default value information. As such, it is compatible with old
(and very old) PHP versions.

Intended for use by extensions to generate one arginfo file for
PHP 8 and one for older versions.
This commit is contained in:
Nikita Popov
2020-10-02 14:40:11 +02:00
parent c137f4b6e4
commit 2e32a09541
+18 -2
View File
@@ -31,7 +31,8 @@ function processStubFile(string $stubFile, Context $context) {
throw new Exception("File $stubFile does not exist");
}
$arginfoFile = str_replace('.stub.php', '', $stubFile) . '_arginfo.h';
$arginfoFile = str_replace('.stub.php', '', $stubFile)
. ($context->legacy ? '_legacy' : '') . '_arginfo.h';
$stubCode = file_get_contents($stubFile);
$stubHash = computeStubHash($stubCode);
$oldStubHash = extractStubHash($arginfoFile);
@@ -42,6 +43,12 @@ function processStubFile(string $stubFile, Context $context) {
initPhpParser();
$fileInfo = parseStubFile($stubCode);
if ($context->legacy) {
foreach ($fileInfo->getAllFuncInfos() as $funcInfo) {
$funcInfo->discardInfoForOldPhpVersions();
}
}
$arginfoCode = generateArgInfoCode($fileInfo, $stubHash);
file_put_contents($arginfoFile, $arginfoCode);
@@ -534,6 +541,14 @@ class FuncInfo {
return $flags;
}
public function discardInfoForOldPhpVersions(): void {
$this->return->type = null;
foreach ($this->args as $arg) {
$arg->type = null;
$arg->defaultValue = null;
}
}
}
class ClassInfo {
@@ -1148,10 +1163,11 @@ function initPhpParser() {
}
$optind = null;
$options = getopt("f", ["force-regeneration", "parameter-stats"], $optind);
$options = getopt("f", ["force-regeneration", "parameter-stats", "legacy"], $optind);
$context = new Context;
$printParameterStats = isset($options["parameter-stats"]);
$context->legacy = isset($options["legacy"]);
$context->forceRegeneration =
isset($options["f"]) || isset($options["force-regeneration"]) || $printParameterStats;