From af28c152695ca54ecbc6474a62441bb516723ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 10 Apr 2026 23:06:27 +0200 Subject: [PATCH 1/2] gen_stub: fix invalid C variable name for namespaced types in union/intersection type list When generating a union or intersection type list with multiple class types, the variable holding each zend_string* was declared using toVarEscapedName() (backslashes replaced by underscores), but the subsequent ZEND_TYPE_INIT_CLASS() reference used toEscapedName() (backslashes escaped as \\), producing an invalid C identifier. --- build/gen_stub.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index ce1a238666109..c189abd03471b 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -2375,8 +2375,8 @@ protected function getTypeCode(string $variableLikeName, string &$code): string $code .= "\t{$variableLikeType}_{$variableLikeName}_type_list->num_types = $classTypeCount;\n"; foreach ($arginfoType->classTypes as $k => $classType) { - $escapedClassName = $classType->toEscapedName(); - $code .= "\t{$variableLikeType}_{$variableLikeName}_type_list->types[$k] = (zend_type) ZEND_TYPE_INIT_CLASS({$variableLikeType}_{$variableLikeName}_class_{$escapedClassName}, 0, 0);\n"; + $varEscapedClassName = $classType->toVarEscapedName(); + $code .= "\t{$variableLikeType}_{$variableLikeName}_type_list->types[$k] = (zend_type) ZEND_TYPE_INIT_CLASS({$variableLikeType}_{$variableLikeName}_class_{$varEscapedClassName}, 0, 0);\n"; } $typeMaskCode = $this->type->toArginfoType()->toTypeMask(); From b7300b4956fc4873caf6cbb26d310e99edb6d511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 10 Apr 2026 23:07:14 +0200 Subject: [PATCH 2/2] gen_stub: support use statements in stub files Stmt\Use_ and Stmt\GroupUse nodes were not handled in handleStatements(), causing an "Unexpected node" exception when use statements appeared in stub files. Since NameResolver resolves all names to their fully qualified form before handleStatements() runs, these nodes can simply be skipped. --- build/gen_stub.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build/gen_stub.php b/build/gen_stub.php index c189abd03471b..5230ef78ef776 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -4387,6 +4387,11 @@ private function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPri } } + if ($stmt instanceof Stmt\Use_ || $stmt instanceof Stmt\GroupUse) { + // use statements are resolved by NameResolver before this point + continue; + } + throw new Exception("Unexpected node {$stmt->getType()}"); } if (!empty($conds)) {