diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-02 14:40:11 +0200 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-02 15:14:02 +0200 |
| commit | 2e32a0954147260a156ba6c196e4cd8df41bc869 (patch) | |
| tree | b505874ac9590e0ff4fba78b2e93bd1c2d975a1b /build/gen_stub.php | |
| parent | c137f4b6e4d10f49220ed61ffcd0ea31ef2329af (diff) | |
| download | php-git-2e32a0954147260a156ba6c196e4cd8df41bc869.tar.gz | |
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.
Diffstat (limited to 'build/gen_stub.php')
| -rwxr-xr-x | build/gen_stub.php | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/build/gen_stub.php b/build/gen_stub.php index bd8b33759f..4f3a8514b4 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -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; |
