[php-src] PR #21717: gen_stub: fix union/intersection types with namespaced classes and support use statements

From: Date: Fri, 10 Apr 2026 21:08:11 +0000
Subject: [php-src] PR #21717: gen_stub: fix union/intersection types with namespaced classes and support use statements
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35667@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21717 Author: GromNaN ## Summary Two fixes for build/gen_stub.php related to union and intersection types with namespaced class names in stub files. **Fix 1: Invalid C variable name for namespaced types in type lists** When generating a union or intersection type list with multiple class types, the zend_string* variable was declared using toVarEscapedName() (backslashes replaced by underscores), but the subsequent ZEND_TYPE_INIT_CLASS() call referenced it using toEscapedName() (backslashes escaped as \\), producing an invalid C identifier and broken generated code. **Fix 2: Support use statements in stub files** Stmt\Use_ and Stmt\GroupUse nodes were not handled in handleStatements(), causing an "Unexpected node Stmt_Use" 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. Together these fixes allow stub files to use short class names via use statements, and correctly generate intersection/union type declarations for properties with namespaced class types such as: ```php use MongoDB\Driver\Exception\Exception as DriverException; class CommandFailedEvent { public readonly \Exception&DriverException $error; } ```

« previous php.git-pulls (#35667) next »