[php-src] master: build/gen_stub: include attribute arguments in synopsis modifiers (#22418)
| From: | Jordi Kroon via GitHub | Date: | Sun, 20 Sep 2026 06:31:58 +0000 |
| Subject: | [php-src] master: build/gen_stub: include attribute arguments in synopsis modifiers (#22418) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141303@lists.php.net to get a copy of this message | ||
Author: Jordi Kroon (jordikroon)
Committer: GitHub (web-flow)
Pusher: kocsismate
Date: 2026-09-20T08:31:55+02:00
Commit: https://github.com/php/php-src/commit/64411588b1452a5d781ec7d75616624cec12b175
Raw diff: https://github.com/php/php-src/commit/64411588b1452a5d781ec7d75616624cec12b175.diff
build/gen_stub: include attribute arguments in synopsis modifiers (#22418)
Changed paths:
M build/gen_stub.php
Diff:
diff --git a/build/gen_stub.php b/build/gen_stub.php
index ee1f6914aa28..cb41618867c1 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);