From 4e5214b2217bb9493f3b007df9cf0ebe1ce9f0a9 Mon Sep 17 00:00:00 2001 From: Michael Telgmann Date: Thu, 30 Oct 2025 16:05:43 +0100 Subject: [PATCH 1/3] fix: Allow variadic syntax in PHPDoc parameter annotation in `gen_stub.php` Closes #20277 --- build/gen_stub.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index a83c6c13bf8c1..c4f4806b7c85d 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -3323,12 +3323,12 @@ public function getType(): string { $matches = []; if ($this->name === "param") { - preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)\s*(?:[{(]|\$\w+).*$/', $value, $matches); + preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)\s*(?[{(]|(\.\.\.)?\$\w+).*$/', $value, $matches); } elseif ($this->name === "return" || $this->name === "var") { - preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)/', $value, $matches); + preg_match('/^\s*(?[\w\|\\\\\[\]<>, ]+)/', $value, $matches); } - if (!isset($matches[1])) { + if (!isset($matches["type"])) { throw new Exception("@$this->name doesn't contain a type or has an invalid format \"$value\""); } @@ -3345,7 +3345,7 @@ public function getVariableName(): string { if ($this->name === "param") { // Allow for parsing extended types like callable(string):mixed in docblocks - preg_match('/^\s*(?[\w\|\\\\]+(?\((?(?:(?&parens)|[^(){}[\]]*+))++\)|\{(?&inparens)\}|\[(?&inparens)\])*+(?::(?&type))?)\s*\$(?\w+).*$/', $value, $matches); + preg_match('/^\s*(?[\w\|\\\\]+(?\((?(?:(?&parens)|[^(){}[\]]*+))++\)|\{(?&inparens)\}|\[(?&inparens)\])*+(?::(?&type))?)\s*(\.\.\.)?\$(?\w+).*$/', $value, $matches); } elseif ($this->name === "prefer-ref") { preg_match('/^\s*\$(?\w+).*$/', $value, $matches); } From ae179e48fffc944b6693e2500efdcb8d25bbebab Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 4 Dec 2025 14:16:26 +0100 Subject: [PATCH 2/3] Simplify --- build/gen_stub.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index c4f4806b7c85d..c119969446301 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -3323,12 +3323,12 @@ public function getType(): string { $matches = []; if ($this->name === "param") { - preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)\s*(?[{(]|(\.\.\.)?\$\w+).*$/', $value, $matches); + preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)\s*([{(]|(\.\.\.)?\$\w+).*$/', $value, $matches); } elseif ($this->name === "return" || $this->name === "var") { - preg_match('/^\s*(?[\w\|\\\\\[\]<>, ]+)/', $value, $matches); + preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)/', $value, $matches); } - if (!isset($matches["type"])) { + if (!isset($matches[1])) { throw new Exception("@$this->name doesn't contain a type or has an invalid format \"$value\""); } From f50b86f7db120a5b78547a6f63903e3f5cdac300 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 4 Dec 2025 14:23:11 +0100 Subject: [PATCH 3/3] Also re-add non-capture group Not that it matters, we just want no unrelated changes. --- build/gen_stub.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index c119969446301..9d6bd2ce3935a 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -3323,7 +3323,7 @@ public function getType(): string { $matches = []; if ($this->name === "param") { - preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)\s*([{(]|(\.\.\.)?\$\w+).*$/', $value, $matches); + preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)\s*(?:[{(]|(\.\.\.)?\$\w+).*$/', $value, $matches); } elseif ($this->name === "return" || $this->name === "var") { preg_match('/^\s*([\w\|\\\\\[\]<>, ]+)/', $value, $matches); }