Commit cc77b6fd1be for php.net
commit cc77b6fd1be1fb28d9640739653a964ad5ad535c
Author: Daniel Scherzer <daniel.e.scherzer@gmail.com>
Date: Sat Mar 21 14:59:13 2026 -0700
gen_stub: move constructors above other methods
In preparation for using constructor property promotion
diff --git a/build/gen_stub.php b/build/gen_stub.php
index 7808929c86c..b1bbb3f5d46 100755
--- a/build/gen_stub.php
+++ b/build/gen_stub.php
@@ -231,11 +231,6 @@ class ArrayType extends SimpleType {
private readonly Type $keyType;
private readonly Type $valueType;
- public static function createGenericArray(): self
- {
- return new ArrayType(Type::fromString("int|string"), Type::fromString("mixed|ref"));
- }
-
public function __construct(Type $keyType, Type $valueType)
{
parent::__construct("array", true);
@@ -244,6 +239,11 @@ public function __construct(Type $keyType, Type $valueType)
$this->valueType = $valueType;
}
+ public static function createGenericArray(): self
+ {
+ return new ArrayType(Type::fromString("int|string"), Type::fromString("mixed|ref"));
+ }
+
public function toOptimizerTypeMask(): string {
$typeMasks = [
parent::toOptimizerTypeMask(),
@@ -270,6 +270,11 @@ class SimpleType {
public readonly string $name;
public readonly bool $isBuiltin;
+ protected function __construct(string $name, bool $isBuiltin) {
+ $this->name = $name;
+ $this->isBuiltin = $isBuiltin;
+ }
+
public static function fromNode(Node $node): SimpleType {
if ($node instanceof Node\Name) {
if ($node->toLowerString() === 'static') {
@@ -364,11 +369,6 @@ public static function null(): SimpleType
return new SimpleType("null", true);
}
- protected function __construct(string $name, bool $isBuiltin) {
- $this->name = $name;
- $this->isBuiltin = $isBuiltin;
- }
-
public function isScalar(): bool {
return $this->isBuiltin && in_array($this->name, ["null", "false", "true", "bool", "int", "float"], true);
}
@@ -502,6 +502,14 @@ class Type {
public readonly array $types;
public readonly bool $isIntersection;
+ /**
+ * @param SimpleType[] $types
+ */
+ private function __construct(array $types, bool $isIntersection) {
+ $this->types = $types;
+ $this->isIntersection = $isIntersection;
+ }
+
public static function fromNode(Node $node): Type {
if ($node instanceof Node\UnionType || $node instanceof Node\IntersectionType) {
$nestedTypeObjects = array_map(Type::fromNode(...), $node->types);
@@ -573,14 +581,6 @@ public static function fromString(string $typeString): self {
return new Type($simpleTypes, $isIntersection);
}
- /**
- * @param SimpleType[] $types
- */
- private function __construct(array $types, bool $isIntersection) {
- $this->types = $types;
- $this->isIntersection = $isIntersection;
- }
-
public function isScalar(): bool {
return !array_any($this->types, static fn (SimpleType $type): bool => !$type->isScalar());
}
@@ -2216,6 +2216,19 @@ class EvaluatedValue
/** @var ConstInfo[] */
public array $originatingConsts;
+ /**
+ * @param mixed $value
+ * @param ConstInfo[] $originatingConsts
+ */
+ private function __construct($value, SimpleType $type, Expr $expr, array $originatingConsts, bool $isUnknownConstValue)
+ {
+ $this->value = $value;
+ $this->type = $type;
+ $this->expr = $expr;
+ $this->originatingConsts = $originatingConsts;
+ $this->isUnknownConstValue = $isUnknownConstValue;
+ }
+
/**
* @param array<string, ConstInfo> $allConstInfos
*/
@@ -2322,19 +2335,6 @@ public static function null(): EvaluatedValue
return new self(null, SimpleType::null(), new Expr\ConstFetch(new Node\Name('null')), [], false);
}
- /**
- * @param mixed $value
- * @param ConstInfo[] $originatingConsts
- */
- private function __construct($value, SimpleType $type, Expr $expr, array $originatingConsts, bool $isUnknownConstValue)
- {
- $this->value = $value;
- $this->type = $type;
- $this->expr = $expr;
- $this->originatingConsts = $originatingConsts;
- $this->isUnknownConstValue = $isUnknownConstValue;
- }
-
public function initializeZval(string $zvalName, bool $alreadyExists = false, string $forStringDef = ''): string
{
$cExpr = $this->getCExpr();