From 5c5a0fd87169c3d305d95a5b7c7e2aead747e592 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 5 Sep 2025 11:49:33 +0200 Subject: [PATCH 1/2] Fix Xml_* function handler phpdoc --- extractor/extract.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/extractor/extract.php b/extractor/extract.php index 9e96a42f..219e7702 100755 --- a/extractor/extract.php +++ b/extractor/extract.php @@ -286,6 +286,7 @@ public function clear(): void continue; } $functions[strtolower($namespacedName)] = $pathPart; + $stmt = $this->filterFunctionPhpDocs($stmt); } else { throw new \Exception(sprintf('Unhandled node type %s in %s on line %s.', get_class($stmt), $stubPath, $stmt->getLine())); } @@ -820,6 +821,44 @@ private function filterClassPhpDocs(Node\Stmt\ClassLike $class): Node\Stmt\Class return $class; } + private function filterFunctionPhpDocs(Node\Stmt\Function_ $function): Node\Stmt\Function_ + { + $namespacedName = $function->namespacedName->toString(); + if (in_array($namespacedName, [ + 'xml_set_element_handler', + 'xml_set_character_data_handler', + 'xml_set_processing_instruction_handler', + 'xml_set_default_handler', + 'xml_set_unparsed_entity_decl_handler', + 'xml_set_notation_decl_handler', + 'xml_set_external_entity_ref_handler', + 'xml_set_start_namespace_decl_handler', + 'xml_set_end_namespace_decl_handler', + ], true)) { + $comments = $function->getAttribute('comments'); + if (null !== $comments) { + $function->setAttribute('comments', array_map( + fn (Comment\Doc $doc): Comment\Doc => new Comment\Doc( + str_replace( + '@param callable $', + '@param callable|string|null $', + $doc->getText(), + ), + $doc->getStartLine(), + $doc->getStartFilePos(), + $doc->getStartTokenPos(), + $doc->getEndLine(), + $doc->getEndFilePos(), + $doc->getEndTokenPos(), + ), + $comments + )); + } + } + + return $function; + } + private function parseDocComment(string $docComment): PhpDocNode { $tokens = new TokenIterator($this->phpDocLexer->tokenize($docComment)); From 0beec0ffb183c2bca47646cce6cd5c80592a9e73 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 5 Sep 2025 12:15:05 +0200 Subject: [PATCH 2/2] Update stub --- extractor/extract.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extractor/extract.php b/extractor/extract.php index 219e7702..c058967d 100755 --- a/extractor/extract.php +++ b/extractor/extract.php @@ -835,6 +835,11 @@ private function filterFunctionPhpDocs(Node\Stmt\Function_ $function): Node\Stmt 'xml_set_start_namespace_decl_handler', 'xml_set_end_namespace_decl_handler', ], true)) { + /** + * Stub was updated in PHP 8.4, but the support for `callable|string|null` already exists before. + * + * @see https://github.com/php/php-src/pull/12340/files#diff-2c2d210a6a8bc8eae404fa6938be724484865b47cc574d94d24e2c18524c1b40 + */ $comments = $function->getAttribute('comments'); if (null !== $comments) { $function->setAttribute('comments', array_map(