From b70d1e6a3b8368f408ed1d2240215c9037146e6c Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 4 Oct 2024 18:05:23 -0700 Subject: [PATCH 01/12] gen_stub: remove unused `VariableLike::getVariableTypeCode()` --- build/gen_stub.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index c30c491935298..88582f9552e93 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -2389,8 +2389,6 @@ public function __construct( $this->exposedDocComment = $exposedDocComment; } - abstract protected function getVariableTypeCode(): string; - abstract protected function getVariableTypeName(): string; abstract protected function getFieldSynopsisDefaultLinkend(): string; @@ -2605,11 +2603,6 @@ protected function getVariableTypeName(): string return "constant"; } - protected function getVariableTypeCode(): string - { - return "const"; - } - protected function getFieldSynopsisDefaultLinkend(): string { $className = str_replace(["\\", "_"], ["-", "-"], $this->name->class->toLowerString()); @@ -3042,11 +3035,6 @@ public function __construct( parent::__construct($flags, $type, $phpDocType, $link, $phpVersionIdMinimumCompatibility, $attributes, $exposedDocComment); } - protected function getVariableTypeCode(): string - { - return "property"; - } - protected function getVariableTypeName(): string { return "property"; From 813d8f41f3c07e917c8d580f0dff3d4a685650f5 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 4 Oct 2024 18:09:18 -0700 Subject: [PATCH 02/12] gen_stub: remove unused `SimpleType::void()` --- build/gen_stub.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 88582f9552e93..6ec15bd98e646 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -365,11 +365,6 @@ public static function object(): SimpleType return new SimpleType("object", true); } - public static function void(): SimpleType - { - return new SimpleType("void", true); - } - protected function __construct(string $name, bool $isBuiltin) { $this->name = $name; $this->isBuiltin = $isBuiltin; From a9265bec4a9a3ef2e0f7a7ef1583655b9cb86e56 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 4 Oct 2024 18:11:17 -0700 Subject: [PATCH 03/12] gen_stub: inline single-use static SimpleType constructors The following one-line methods, only used in `SimpleType::fromValue()`, were inlined: * `SimpleType::bool()` * `SimpleType::int()` * `SimpleType::float()` * `SimpleType::string()` * `SimpleType::array()` * `SimpleType::object()` Doing so removes an unneeded level of indirection and helps simplify the class. --- build/gen_stub.php | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 6ec15bd98e646..fa3772b4e9948 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -314,17 +314,17 @@ public static function fromValue($value): SimpleType case "NULL": return SimpleType::null(); case "boolean": - return SimpleType::bool(); + return new SimpleType("bool", true); case "integer": - return SimpleType::int(); + return new SimpleType("int", true); case "double": - return SimpleType::float(); + return new SimpleType("float", true); case "string": - return SimpleType::string(); + return new SimpleType("string", true); case "array": - return SimpleType::array(); + return new SimpleType("array", true); case "object": - return SimpleType::object(); + return new SimpleType("object", true); default: throw new Exception("Type \"" . gettype($value) . "\" cannot be inferred based on value"); } @@ -335,36 +335,6 @@ public static function null(): SimpleType return new SimpleType("null", true); } - public static function bool(): SimpleType - { - return new SimpleType("bool", true); - } - - public static function int(): SimpleType - { - return new SimpleType("int", true); - } - - public static function float(): SimpleType - { - return new SimpleType("float", true); - } - - public static function string(): SimpleType - { - return new SimpleType("string", true); - } - - public static function array(): SimpleType - { - return new SimpleType("array", true); - } - - public static function object(): SimpleType - { - return new SimpleType("object", true); - } - protected function __construct(string $name, bool $isBuiltin) { $this->name = $name; $this->isBuiltin = $isBuiltin; From ed44c333e2eb4022f1d8eb3b733a0024e64a026b Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 4 Oct 2024 18:16:11 -0700 Subject: [PATCH 04/12] gen_stub: inline single-use `::setTypes()` methods Both `ArgInfo::setTypes()` and `ReturnInfo::setTypes()` were private methods only called in the applicable class's constructor. They had no special logic that benefited from existing as a separate method, and just added a level of indirection. Inline the uses and remove the methods. --- build/gen_stub.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index fa3772b4e9948..4fb7c1fc546d8 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -819,7 +819,8 @@ public function __construct( $this->name = $name; $this->sendBy = $sendBy; $this->isVariadic = $isVariadic; - $this->setTypes($type, $phpDocType); + $this->type = $type; + $this->phpDocType = $phpDocType; $this->defaultValue = $defaultValue; $this->attributes = $attributes; } @@ -884,12 +885,6 @@ public function getDefaultValueAsMethodSynopsisString(): ?string { return $this->defaultValue; } - - private function setTypes(?Type $type, ?Type $phpDocType): void - { - $this->type = $type; - $this->phpDocType = $phpDocType; - } } interface VariableLikeName { @@ -1146,7 +1141,9 @@ class ReturnInfo { public function __construct(bool $byRef, ?Type $type, ?Type $phpDocType, bool $tentativeReturnType, ?string $refcount) { $this->byRef = $byRef; - $this->setTypes($type, $phpDocType, $tentativeReturnType); + $this->type = $type; + $this->phpDocType = $phpDocType; + $this->tentativeReturnType = $tentativeReturnType; $this->setRefcount($refcount); } @@ -1160,13 +1157,6 @@ public function getMethodSynopsisType(): ?Type { return $this->type ?? $this->phpDocType; } - private function setTypes(?Type $type, ?Type $phpDocType, bool $tentativeReturnType): void - { - $this->type = $type; - $this->phpDocType = $phpDocType; - $this->tentativeReturnType = $tentativeReturnType; - } - private function setRefcount(?string $refcount): void { $type = $this->phpDocType ?? $this->type; From ab78bd32485739c6cb5ee72e34c3a51525f63489 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 4 Oct 2024 18:21:37 -0700 Subject: [PATCH 05/12] gen_stub: inline single-use `VariableLike::addTypeToFieldSynopsis()` method Protected method not overridden in any subclasses, so could be made private, but the method is short enough and simple enough that it can just be inlined. --- build/gen_stub.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 4fb7c1fc546d8..7c5d3534a7294 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -2355,16 +2355,6 @@ abstract protected function getFieldSynopsisValueString(array $allConstInfos): ? abstract public function discardInfoForOldPhpVersions(?int $minimumPhpVersionIdCompatibility): void; - protected function addTypeToFieldSynopsis(DOMDocument $doc, DOMElement $fieldsynopsisElement): void - { - $type = $this->phpDocType ?? $this->type; - - if ($type) { - $fieldsynopsisElement->appendChild(new DOMText("\n ")); - $fieldsynopsisElement->appendChild($type->getTypeForDoc($doc)); - } - } - /** * @return array */ @@ -2443,7 +2433,11 @@ public function getFieldSynopsisElement(DOMDocument $doc, array $allConstInfos): $this->addModifiersToFieldSynopsis($doc, $fieldsynopsisElement); - $this->addTypeToFieldSynopsis($doc, $fieldsynopsisElement); + $type = $this->phpDocType ?? $this->type; + if ($type) { + $fieldsynopsisElement->appendChild(new DOMText("\n ")); + $fieldsynopsisElement->appendChild($type->getTypeForDoc($doc)); + } $varnameElement = $doc->createElement("varname", $this->getFieldSynopsisName()); if ($this->link) { From 3b3983450cc9adad5d67fc322613322d19040a5c Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 4 Oct 2024 18:27:43 -0700 Subject: [PATCH 06/12] gen_stub: refactor `Type::tryToSimpleType()`, eliminate `::getWithoutNull()` `Type::tryToSimpleType()` tries to convert a type holding multiple simple types into a single simple type, with the following logic - if all of the inner types represent `null`, return the first of those - if all but one of the inner types represent `null`, return the non-null type - otherwise, return `null` Previously, it did this with a helper method `::getWithoutNull()`, that constructed a new `Type` containing only the inner types that did not represent `null`. However, the only thing the newly created object was used for was extracting the types it contains, so the actual object creation just adds overhead. Merge `Type::getWithoutNull()` into `Type::tryToSimpleType()` and clean up to avoid creating an unneeded object. --- build/gen_stub.php | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 7c5d3534a7294..353c63174370b 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -634,28 +634,19 @@ public function isNullable(): bool { return false; } - public function getWithoutNull(): Type { - return new Type( - array_values( - array_filter( - $this->types, - function(SimpleType $type) { - return !$type->isNull(); - } - ) - ), - false - ); - } - public function tryToSimpleType(): ?SimpleType { - $withoutNull = $this->getWithoutNull(); + $nonNullTypes = array_filter( + $this->types, + function(SimpleType $type) { + return !$type->isNull(); + } + ); /* type has only null */ - if (count($withoutNull->types) === 0) { + if (count($nonNullTypes) === 0) { return $this->types[0]; } - if (count($withoutNull->types) === 1) { - return $withoutNull->types[0]; + if (count($nonNullTypes) === 1) { + return reset($nonNullTypes); } return null; } From b7239d03e3c1ebdd4c760ec1754157aaa338fece Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 4 Oct 2024 18:34:26 -0700 Subject: [PATCH 07/12] gen_stub: convert `ArgInfo::$sendBy` to a string Instead of using integers that then need to be converted to the string representation via `::getSendByString()`, just always store a string, eliminating the conversion method and replacing it with property access. --- build/gen_stub.php | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 353c63174370b..3f5bcbd5d02f7 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -782,12 +782,12 @@ public function toTypeMask(): string { } class ArgInfo { - const SEND_BY_VAL = 0; - const SEND_BY_REF = 1; - const SEND_PREFER_REF = 2; + const SEND_BY_VAL = "0"; + const SEND_BY_REF = "1"; + const SEND_PREFER_REF = "ZEND_SEND_PREFER_REF"; public string $name; - public int $sendBy; + public string $sendBy; public bool $isVariadic; public ?Type $type; public ?Type $phpDocType; @@ -800,7 +800,7 @@ class ArgInfo { */ public function __construct( string $name, - int $sendBy, + string $sendBy, bool $isVariadic, ?Type $type, ?Type $phpDocType, @@ -824,18 +824,6 @@ public function equals(ArgInfo $other): bool { && $this->defaultValue === $other->defaultValue; } - public function getSendByString(): string { - switch ($this->sendBy) { - case self::SEND_BY_VAL: - return "0"; - case self::SEND_BY_REF: - return "1"; - case self::SEND_PREFER_REF: - return "ZEND_SEND_PREFER_REF"; - } - throw new Exception("Invalid sendBy value"); - } - public function getMethodSynopsisType(): Type { if ($this->type) { return $this->type; @@ -5035,14 +5023,14 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string { if ($simpleArgType->isBuiltin) { $code .= sprintf( "\tZEND_%s_TYPE_INFO%s(%s, %s, %s, %d%s)\n", - $argKind, $argDefaultKind, $argInfo->getSendByString(), $argInfo->name, + $argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name, $simpleArgType->toTypeCode(), $argType->isNullable(), $argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : "" ); } else { $code .= sprintf( "\tZEND_%s_OBJ_INFO%s(%s, %s, %s, %d%s)\n", - $argKind,$argDefaultKind, $argInfo->getSendByString(), $argInfo->name, + $argKind,$argDefaultKind, $argInfo->sendBy, $argInfo->name, $simpleArgType->toEscapedName(), $argType->isNullable(), $argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : "" ); @@ -5052,14 +5040,14 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string { if ($arginfoType->hasClassType()) { $code .= sprintf( "\tZEND_%s_OBJ_TYPE_MASK(%s, %s, %s, %s%s)\n", - $argKind, $argInfo->getSendByString(), $argInfo->name, + $argKind, $argInfo->sendBy, $argInfo->name, $arginfoType->toClassTypeString(), $arginfoType->toTypeMask(), !$argInfo->isVariadic ? ", " . $argInfo->getDefaultValueAsArginfoString() : "" ); } else { $code .= sprintf( "\tZEND_%s_TYPE_MASK(%s, %s, %s, %s)\n", - $argKind, $argInfo->getSendByString(), $argInfo->name, + $argKind, $argInfo->sendBy, $argInfo->name, $arginfoType->toTypeMask(), $argInfo->getDefaultValueAsArginfoString() ); @@ -5068,7 +5056,7 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string { } else { $code .= sprintf( "\tZEND_%s_INFO%s(%s, %s%s)\n", - $argKind, $argDefaultKind, $argInfo->getSendByString(), $argInfo->name, + $argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name, $argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : "" ); } From 7bb3b0d15a1d47c59420db7c5fc0e53ff402eba7 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Mon, 7 Oct 2024 18:43:49 -0700 Subject: [PATCH 08/12] gen_stub: make some methods only used within their class private * `FuncInfo::hasParamWithUnknownDefaultValue()` * `FuncInfo::getFramelessFunctionInfosName()` * `ClassInfo::getClassSynopsisReference()` --- build/gen_stub.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 3f5bcbd5d02f7..b98178ff34eed 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -1275,7 +1275,7 @@ public function getModifierNames(): array return $result; } - public function hasParamWithUnknownDefaultValue(): bool + private function hasParamWithUnknownDefaultValue(): bool { foreach ($this->args as $arg) { if ($arg->defaultValue && !$arg->hasProperDefaultValue()) { @@ -1355,7 +1355,7 @@ public function getFramelessDeclaration(FuncInfo $funcInfo): ?string { return $code; } - public function getFramelessFunctionInfosName(): string { + private function getFramelessFunctionInfosName(): string { return $this->name->getFramelessFunctionInfosName(); } @@ -3819,7 +3819,7 @@ public static function getClassSynopsisFilename(Name $name): string { return strtolower(str_replace("_", "-", implode('-', $name->getParts()))); } - public static function getClassSynopsisReference(Name $name): string { + private static function getClassSynopsisReference(Name $name): string { return "class." . self::getClassSynopsisFilename($name); } From 262674f2c9ee779c13c60fc77064ef6031312880 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Mon, 7 Oct 2024 18:50:18 -0700 Subject: [PATCH 09/12] gen_stub: stop cloning `ExposedDocComment` objects The objects are immutable, and thus can be safely reused when held by an object that gets cloned. Remove the unneeded cloning, and document this fact about the class, noting that the property should be considered `readonly`. Not actually using `readonly` to maintain PHP 7.4 support. --- build/gen_stub.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index b98178ff34eed..d1d55fabaac90 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -2103,9 +2103,6 @@ public function __clone() foreach ($this->framelessFunctionInfos as $key => $framelessFunctionInfo) { $this->framelessFunctionInfos[$key] = clone $framelessFunctionInfo; } - if ($this->exposedDocComment) { - $this->exposedDocComment = clone $this->exposedDocComment; - } } } @@ -3150,9 +3147,6 @@ public function __clone() foreach ($this->attributes as $key => $attribute) { $this->attributes[$key] = clone $attribute; } - if ($this->exposedDocComment) { - $this->exposedDocComment = clone $this->exposedDocComment; - } } } @@ -4008,10 +4002,6 @@ public function __clone() foreach ($this->attributes as $key => $attribute) { $this->attributes[$key] = clone $attribute; } - - if ($this->exposedDocComment) { - $this->exposedDocComment = clone $this->exposedDocComment; - } } /** @@ -4187,8 +4177,10 @@ public function getVariableName(): string { } } +// Instances of ExposedDocComment are immutable and do not need to be cloned +// when held by an object that is cloned class ExposedDocComment { - private string $docComment; + private /* readonly */ string $docComment; public function __construct(string $docComment) { $this->docComment = $docComment; From d15d5f7fe0f16ee186a5b2f77712b9d242ba2842 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Mon, 7 Oct 2024 19:18:04 -0700 Subject: [PATCH 10/12] gen_stub: remove impossible `Type::__toString()` handling `Type::$types` is typed as an array, and thus can never be `null`. There is no need to have code to handle such a case. --- build/gen_stub.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index d1d55fabaac90..fffa512642419 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -734,10 +734,6 @@ public static function equals(?Type $a, ?Type $b): bool { } public function __toString() { - if ($this->types === null) { - return 'mixed'; - } - $char = $this->isIntersection ? '&' : '|'; return implode($char, array_map( function ($type) { return $type->name; }, From 7dc17ed60a49a82769586259c1f19745342dc6ff Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Mon, 7 Oct 2024 19:35:16 -0700 Subject: [PATCH 11/12] gen_stub: document a bunch of properties as read-only In the hopes that it will be clearer that some of the custom clone handling can be removed the way it was for `ExposedDocComment`, instances of which were immutable, document a bunch of properties of other classes as read-only. --- build/gen_stub.php | 126 ++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index fffa512642419..00a4c85ee0b4b 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -191,8 +191,8 @@ class Context { } class ArrayType extends SimpleType { - public Type $keyType; - public Type $valueType; + public /* readonly */ Type $keyType; + public /* readonly */ Type $valueType; public static function createGenericArray(): self { @@ -230,8 +230,8 @@ public function equals(SimpleType $other): bool { } class SimpleType { - public string $name; - public bool $isBuiltin; + public /* readonly */ string $name; + public /* readonly */ bool $isBuiltin; public static function fromNode(Node $node): SimpleType { if ($node instanceof Node\Name) { @@ -532,8 +532,8 @@ public function equals(SimpleType $other): bool { class Type { /** @var SimpleType[] */ - public array $types; - public bool $isIntersection; + public /* readonly */ array $types; + public /* readonly */ bool $isIntersection; public static function fromNode(Node $node): Type { if ($node instanceof Node\UnionType || $node instanceof Node\IntersectionType) { @@ -744,9 +744,9 @@ function ($type) { return $type->name; }, class ArginfoType { /** @var SimpleType[] $classTypes */ - public array $classTypes; + public /* readonly */ array $classTypes; /** @var SimpleType[] $builtinTypes */ - private array $builtinTypes; + private /* readonly */ array $builtinTypes; /** * @param SimpleType[] $classTypes @@ -782,11 +782,11 @@ class ArgInfo { const SEND_BY_REF = "1"; const SEND_PREFER_REF = "ZEND_SEND_PREFER_REF"; - public string $name; - public string $sendBy; - public bool $isVariadic; + public /* readonly */ string $name; + public /* readonly */ string $sendBy; + public /* readonly */ bool $isVariadic; public ?Type $type; - public ?Type $phpDocType; + public /* readonly */ ?Type $phpDocType; public ?string $defaultValue; /** @var AttributeInfo[] */ public array $attributes; @@ -887,7 +887,7 @@ public function isUnknown(): bool } class ConstName extends AbstractConstName { - public string $const; + public /* readonly */ string $const; public function __construct(?Name $namespace, string $const) { @@ -923,8 +923,8 @@ public function getDeclarationName(): string } class ClassConstName extends AbstractConstName { - public Name $class; - public string $const; + public /* readonly */ Name $class; + public /* readonly */ string $const; public function __construct(Name $class, string $const) { @@ -949,8 +949,8 @@ public function getDeclarationName(): string } class PropertyName implements VariableLikeName { - public Name $class; - public string $property; + public /* readonly */ Name $class; + public /* readonly */ string $property; public function __construct(Name $class, string $property) { @@ -981,7 +981,7 @@ public function isDestructor(): bool; } class FunctionName implements FunctionOrMethodName { - private Name $name; + private /* readonly */ Name $name; public function __construct(Name $name) { $this->name = $name; @@ -1049,8 +1049,8 @@ public function isDestructor(): bool { } class MethodName implements FunctionOrMethodName { - public Name $className; - public string $methodName; + public /* readonly */ Name $className; + public /* readonly */ string $methodName; public function __construct(Name $className, string $methodName) { $this->className = $className; @@ -1108,11 +1108,12 @@ class ReturnInfo { self::REFCOUNT_N, ]; - public bool $byRef; + public /* readonly */ bool $byRef; + // NOT readonly - gets removed when discarding info for older PHP versions public ?Type $type; - public ?Type $phpDocType; - public bool $tentativeReturnType; - public string $refcount; + public /* readonly */ ?Type $phpDocType; + public /* readonly */ bool $tentativeReturnType; + public /* readonly */ string $refcount; public function __construct(bool $byRef, ?Type $type, ?Type $phpDocType, bool $tentativeReturnType, ?string $refcount) { $this->byRef = $byRef; @@ -1159,19 +1160,19 @@ private function setRefcount(?string $refcount): void } class FuncInfo { - public FunctionOrMethodName $name; - public int $classFlags; + public /* readonly */ FunctionOrMethodName $name; + public /* readonly */ int $classFlags; public int $flags; - public ?string $aliasType; + public /* readonly */ ?string $aliasType; public ?FunctionOrMethodName $alias; - public bool $isDeprecated; + public /* readonly */ bool $isDeprecated; public bool $supportsCompileTimeEval; - public bool $verify; + public /* readonly */ bool $verify; /** @var ArgInfo[] */ - public array $args; - public ReturnInfo $return; - public int $numRequiredArgs; - public ?string $cond; + public /* readonly */ array $args; + public /* readonly */ ReturnInfo $return; + public /* readonly */ int $numRequiredArgs; + public /* readonly */ ?string $cond; public bool $isUndocumentable; public ?int $minimumPhpVersionIdCompatibility; /** @var AttributeInfo[] */ @@ -2104,8 +2105,7 @@ public function __clone() class EvaluatedValue { - /** @var mixed */ - public $value; + public /* readonly */ mixed $value; public SimpleType $type; public Expr $expr; public bool $isUnknownConstValue; @@ -2288,12 +2288,12 @@ abstract class VariableLike { public int $flags; public ?Type $type; - public ?Type $phpDocType; - public ?string $link; + public /* readonly */ ?Type $phpDocType; + public /* readonly */ ?string $link; public ?int $phpVersionIdMinimumCompatibility; /** @var AttributeInfo[] */ public array $attributes; - public ?ExposedDocComment $exposedDocComment; + public /* readonly */ ?ExposedDocComment $exposedDocComment; /** * @var AttributeInfo[] $attributes @@ -2468,11 +2468,11 @@ protected function addFlagForVersionsAbove(array $flags, string $flag, int $mini class ConstInfo extends VariableLike { - public ConstOrClassConstName $name; - public Expr $value; + public /* readonly */ ConstOrClassConstName $name; + public /* readonly */ Expr $value; public bool $isDeprecated; public ?string $valueString; - public ?string $cond; + public /* readonly */ ?string $cond; public ?string $cValue; public bool $isUndocumentable; public bool $isFileCacheAllowed; @@ -2828,12 +2828,12 @@ protected function addModifiersToFieldSynopsis(DOMDocument $doc, DOMElement $fie class PropertyInfo extends VariableLike { - public int $classFlags; - public PropertyName $name; - public ?Expr $defaultValue; - public ?string $defaultValueString; - public bool $isDocReadonly; - public bool $isVirtual; + public /* readonly */ int $classFlags; + public /* readonly */ PropertyName $name; + public /* readonly */ ?Expr $defaultValue; + public /* readonly */ ?string $defaultValueString; + public /* readonly */ bool $isDocReadonly; + public /* readonly */ bool $isVirtual; // Map possible variable names to the known string constant, see // ZEND_KNOWN_STRINGS @@ -3147,8 +3147,8 @@ public function __clone() } class EnumCaseInfo { - public string $name; - public ?Expr $value; + public /* readonly */ string $name; + public /* readonly */ ?Expr $value; public function __construct(string $name, ?Expr $value) { $this->name = $name; @@ -3173,9 +3173,9 @@ public function getDeclaration(array $allConstInfos): string { } class AttributeInfo { - public string $class; + public /* readonly */ string $class; /** @var \PhpParser\Node\Arg[] */ - public array $args; + public /* readonly */ array $args; /** @param \PhpParser\Node\Arg[] $args */ public function __construct(string $class, array $args) { @@ -3226,30 +3226,30 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC } class ClassInfo { - public Name $name; + public /* readonly */ Name $name; public int $flags; public string $type; - public ?string $alias; - public ?SimpleType $enumBackingType; - public bool $isDeprecated; + public /* readonly */ ?string $alias; + public /* readonly */ ?SimpleType $enumBackingType; + public /* readonly */ bool $isDeprecated; public bool $isStrictProperties; /** @var AttributeInfo[] */ public array $attributes; public ?ExposedDocComment $exposedDocComment; public bool $isNotSerializable; /** @var Name[] */ - public array $extends; + public /* readonly */ array $extends; /** @var Name[] */ - public array $implements; + public /* readonly */ array $implements; /** @var ConstInfo[] */ - public array $constInfos; + public /* readonly */ array $constInfos; /** @var PropertyInfo[] */ - public array $propertyInfos; + public /* readonly */ array $propertyInfos; /** @var FuncInfo[] */ public array $funcInfos; /** @var EnumCaseInfo[] */ - public array $enumCaseInfos; - public ?string $cond; + public /* readonly */ array $enumCaseInfos; + public /* readonly */ ?string $cond; public ?int $phpVersionIdMinimumCompatibility; public bool $isUndocumentable; @@ -4116,8 +4116,8 @@ public function shouldGenerateLegacyArginfo(): bool { } class DocCommentTag { - public string $name; - public ?string $value; + public /* readonly */ string $name; + public /* readonly */ ?string $value; public function __construct(string $name, ?string $value) { $this->name = $name; From b6d36077970792e130bb17fc92c7380b87791994 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Mon, 7 Oct 2024 19:38:11 -0700 Subject: [PATCH 12/12] gen_stub: remove some misplaced spaces --- build/gen_stub.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 00a4c85ee0b4b..b8ca6effe5e8d 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -965,7 +965,7 @@ public function __toString(): string public function getDeclarationName(): string { - return $this->property; + return $this->property; } } @@ -2572,7 +2572,7 @@ public function getPredefinedConstantTerm(DOMDocument $doc, int $indentationLeve return $termElement; } - public function getPredefinedConstantEntry(DOMDocument $doc, int $indentationLevel): DOMElement { + public function getPredefinedConstantEntry(DOMDocument $doc, int $indentationLevel): DOMElement { $indentation = str_repeat(" ", $indentationLevel); $entryElement = $doc->createElement("entry"); @@ -5073,7 +5073,7 @@ function findEquivalentFuncInfo(array $generatedFuncInfos, FuncInfo $funcInfo): function generateCodeWithConditions( iterable $infos, string $separator, Closure $codeGenerator, ?string $parentCond = null): string { $code = ""; - + // For combining the conditional blocks of the infos with the same condition $openCondition = null; foreach ($infos as $info) {