Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130053 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id DA69F1A00BC for ; Sun, 8 Feb 2026 12:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1770554915; bh=01WBM9dF6TnNVNR6Fm0qOHmC6B38bYc39AmpxahFrdY=; h=From:Subject:Date:To:From; b=cgHgBgQVrhaZtoRmMQFrVViG90uqKDWo5qqpzqUnJrs+fzsuvwFBs82sJ+W2Cq1yV OBId6n4Ztz5E65km4IlI4Cm2zp5FUFPDlwrD+zrHRA6Vwi0rzthT0ih7TgIamyLVBB MFidvLpFVAA6Cff6Yqy9wbP8Kh6LnU5RMVpg5uy1d+E0fgWGcsuLVxs7qBhhOWbuAz A6CuVvyz4DD5Gtt7QB/e41Wsx0KBMP671Ug3jtGGspey9m7CfM6BF00Lh8iGRW8Ex2 V/VMQh72gqsB8EfkRcz3/ch3CG4Ca3JtQzGimuQ9a7Bv/FAa0TQ1SnyiucJWG03Gn2 kFPqLYsvS4a8Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 69161180050 for ; Sun, 8 Feb 2026 12:48:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail.gna.ch (darkcity.gna.ch [84.234.28.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 8 Feb 2026 12:48:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.gna.ch (Postfix) with ESMTP id 82C7C2380A7B for ; Sun, 8 Feb 2026 13:48:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cschneid.com; s=default; t=1770554891; bh=01WBM9dF6TnNVNR6Fm0qOHmC6B38bYc39AmpxahFrdY=; h=From:Subject:Date:To; b=CQoCHhs7wi104GgeqQ0bEcNeCsGoC8Em+UhOM8DcnxIQjmtSWkAgcaoHyRkQF+NIr xHnEdMmXcFtotU/KnR2o03n0LHE4qYfbtHGlUxCLuHiHP/C9PPpoa4nzqqnT2wrqSr 01TD7S9cOhktKTqEzAjvU+fvVhJ4fSyrYKv93OrU= X-Virus-Scanned: amavisd-new at gna.ch Received: from mail.gna.ch ([127.0.0.1]) by localhost (mail.gna.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aIXF6_d0RYuJ for ; Sun, 8 Feb 2026 13:48:10 +0100 (CET) Received: from smtpclient.apple (unknown [IPv6:2a02:1210:2e2d:4d00:e5b9:d3d6:6f6d:1673]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.gna.ch (Postfix) with ESMTPSA id 8595023800EC for ; Sun, 8 Feb 2026 13:48:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=cschneid.com; s=default; t=1770554890; bh=01WBM9dF6TnNVNR6Fm0qOHmC6B38bYc39AmpxahFrdY=; h=From:Subject:Date:To; b=ELMdRPcY1ZHAfFaEwVaDzeYpEu1ju6fZ9rAlgBoU7Abpv8mn4ZDCbM5LsTW4wAMTM 8LeUJmuQkI1oPZ10Z2lIwrasBUKeihC4hdm3tttzi2ktlXnaLUsh2r3hNhFTohvbmf 9KpKbGF8x023EMAvR+tfdME1P7A9hC4LNpSN2kEQ= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.300.41.1.7\)) Subject: [PHP-DEV] Function/Method parameter DocComments Message-ID: Date: Sun, 8 Feb 2026 13:48:10 +0100 To: PHP internals list X-Mailer: Apple Mail (2.3864.300.41.1.7) From: cschneid@cschneid.com (Christian Schneider) I have a proposal where I wanted to check the mood first before I write = an RFC. Background: While looking into better documenting our Web APIs we figured our = preferred solution is parameter typing plus DocComments and do both = basic checks on input values (e.g. string vs. int vs. array) and = automatically generate OpenAPI docs. So we ended up with something like /** * Search for entries matching query * @param $query Terms to search for in database * @param $num Maximum number of entries returned, default is 10 */ function api_search(string $query, ?int $num =3D 10) { ... } The downside of this is that the parameters have to be mentioned twice = (DocComment and parameter list) and the documentation can diverge from = the implementation. So we looked into using parameters DocComments like /** * Search for entries matching query */ function api_search( string $query /** Terms to search for in database */, ?int $num =3D 10 /** Maximum number of entries returned */, ) { ... } and realized that this is currently not supported. Part 1: When I looked at the parser I realized that PHP already had the syntax = in place for this and it was only missing a) storing the DocComments with the parameters (zend_arg_info) b) providing a method getDocComment() in ReflectionParameter c) allowing DocComments *behind* the parameter instead of before them. While part a) and b) are pretty straightforward I also slightly changed = the syntax to allow the DocComments *after* the parameter definition but = *before* the comma starting the next parameter. This keeps the = implementation very simple with the limitation of having to move the = comma behind the DocComment. Rationale for c) We strongly favored the comment to be behind instead of = before the parameter name + default value and found the trailing comma a = valid compromise. Part 2: I realized that PHP already had (almost) everything in place to also = have DocComments for the internal functions. So I extended zend_internal_arg_info and zend_internal_function_info to = allow this. Part 3: Then I went down the rabbit hole and wrote a script to extract the = information from the doc-en DocBook source and add them to the stub = files. To do this I added a script build/add_doccomments.php and changed = gen_stub.php to use the new macros when applicable. Implementation: You can find the code at = https://github.com/php/php-src/compare/master...chschneider:php-src:param-= doccomment-all with the 3 first commits representing the 3 parts above and the 4th = commit containing the files automatically generated by the = add_doccomments.php and gen_stub.php build scripts so you don't need to = run them. Missing part: - Add tests for ReflectionParameter::getDocComment() - Include add_doccomments.php in the build process, currently is has to = be called manually. Backwards compatibility: As I added a field to the Zend arg_info structure it is an ABI change = which needs external modules to be recompiled to match it. I assume this is acceptable for PHP 8.6, correct? Otherwise the only change is the additional method getDocComment() for = ReflectionParameter, everything else is backwards compatible. Is there interest in the community to add this to the next PHP version? Should I rewrite this into an RFC or are the other = comments/recommendations before I do that? Regards, - Chris