Commit 64411588b14 for php.net
commit 64411588b1452a5d781ec7d75616624cec12b175
Author: Jordi Kroon <jkroon@onyourmarks.agency>
Date: Sun Sep 20 02:31:55 2026 -0400
build/gen_stub: include attribute arguments in synopsis modifiers (#22418)
diff --git a/build/gen_stub.php b/build/gen_stub.php
index ee1f6914aa2..cb41618867c 100755
--- a/build/gen_stub.php
+++ b/build/gen_stub.php
@@ -2169,7 +2169,7 @@ public function getMethodSynopsisElement(DOMDocument $doc): ?DOMElement {
$methodSynopsis->appendChild($methodparam);
foreach ($arg->attributes as $attribute) {
- $attribute = $doc->createElement("modifier", "#[\\" . $attribute->class . "]");
+ $attribute = $doc->createElement("modifier", (string) $attribute);
$attribute->setAttribute("role", "attribute");
$methodparam->appendChild($attribute);
@@ -3355,6 +3355,24 @@ public function __construct(
private readonly array $args,
) {}
+ public function __toString(): string {
+ $code = '#[\\' . $this->class;
+ if (!empty($this->args)) {
+ $prettyPrinter = new Standard;
+ $args = [];
+ foreach ($this->args as $arg) {
+ $argStr = $prettyPrinter->prettyPrintExpr($arg->value);
+ if ($arg->name !== null) {
+ $argStr = $arg->name->name . ': ' . $argStr;
+ }
+ $args[] = $argStr;
+ }
+ $code .= '(' . implode(', ', $args) . ')';
+ }
+ $code .= ']';
+ return $code;
+ }
+
/**
* @param array<string, ConstInfo> $allConstInfos
* @param array<string, string> &$declaredStrings Map of string content to
@@ -4407,6 +4425,7 @@ public function getLegacyVersion(): FileInfo {
public static function parseStubFile(string $code): FileInfo {
$parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative());
$nodeTraverser = new PhpParser\NodeTraverser;
+ $nodeTraverser->addVisitor(new PhpParser\NodeVisitor\CloningVisitor);
$nodeTraverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
$prettyPrinter = new class extends Standard {
protected function pName_FullyQualified(Name\FullyQualified $node): string {
@@ -4415,7 +4434,7 @@ protected function pName_FullyQualified(Name\FullyQualified $node): string {
};
$stmts = $parser->parse($code);
- $nodeTraverser->traverse($stmts);
+ $stmts = $nodeTraverser->traverse($stmts);
$fileTags = DocCommentTag::parseDocComments(self::getFileDocComments($stmts));
$fileInfo = new FileInfo($fileTags);