diff --git a/extractor/extract.php b/extractor/extract.php index 9e96a42f..c058967d 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,49 @@ 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)) { + /** + * 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( + 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));