Take the State of PHP 2026 Survey →

DocComments For Function Parameters View as Markdown

Implemented (PHP 8.6)
Authors
Christian Schneider, cschneid@cschneid.com
Date
2026-02-23
Version
1.0.1
Implementation
https://github.com/php/php-src/pull/21279
Source
wiki.php.net/rfc/parameter-doccomments

Vote

Add DocComment support to function parameters as outlined in the RFC? closed
Yes
23
No
0
Abstain
4
27 voters
alexandredaubois Yes 2026-03-17 15:43
ashnazg Yes 2026-03-18 14:01
ayesh Yes 2026-03-15 17:47
beberlei Yes 2026-03-17 10:35
crell Yes 2026-03-16 16:28
dams Yes 2026-03-23 09:09
daniels Abstain 2026-03-21 18:59
derick Yes 2026-03-15 17:41
dharman Yes 2026-03-15 17:03
edorian Yes 2026-03-18 14:39
ericmann Yes 2026-03-19 03:39
galvao Abstain 2026-03-16 16:11
iliaa Yes 2026-03-15 17:05
ilutov Abstain 2026-03-15 17:11
kalle Yes 2026-03-15 17:10
marandall Yes 2026-03-23 11:41
narf Yes 2026-03-16 21:28
ocramius Yes 2026-03-15 17:19
pmjones Yes 2026-03-16 03:59
pollita Abstain 2026-03-25 19:36
ramsey Yes 2026-03-16 00:04
svpernova09 Yes 2026-03-23 15:29
theodorejb Yes 2026-03-15 17:59
timwolla Yes 2026-03-15 17:44
trowski Yes 2026-03-21 18:26
weierophinney Yes 2026-03-15 17:33
yunosh Yes 2026-03-17 09:21

Discussions on the mailing list

[RFC] DocComments For Function Parameters
by Christian Schneider · 11 messages
[VOTE] DocComments For Function Parameters
by Christian Schneider · 2 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:50 UTC

Introduction

PHP supports DocComments with the getDocComment() function in various Reflection classes but not in ReflectionParameter.

Function parameters are currently documented with @param in the function DocComment block:

/**
* Search for entries matching query
* @param string $query  Terms to search for in database
* @param int $num  Maximum number of entries returned, default is 10
*/
function search(string $query, int $num = 10)
{
  ...
}

The downside of this is that the parameters and their types have to be mentioned twice (DocComment and parameter list) and the documentation can diverge from the implementation.

Proposal

We propose adding DocComment support for function parameters (all the way to the end of the parameter definition, i.e. up to the comma starting the next parameter) and a new function in the ReflectionParameter class

public function getDocComment(): string|false {}

Example

This would allow the example above to be written as

<?php
 
/** Search for entries matching query */
function search(
  /** Terms to search for in database    */
  string $query,
  /** Maximum number of entries returned */
  int $num = 10
) {
  return ['foo', 'bar', 'qux'];
}
 
foreach (new ReflectionFunction("search")->getParameters() as $p) {
  echo $p->name . ": " . $p->getDocComment() . "\n";
}
 
?>

This would output

query: /** Terms to search for in database    */
num: /** Maximum number of entries returned */

Example with DocComment after Parameter

The proposal also allows to write the DocComment behind the parameter definition but before the comma starting the next parameter (this is similar to and already supported for property definitions):

<?php
 
/** Search for entries matching query */
function search(
  string $query /** Terms to search for in database    */,
  int $num = 10 /** Maximum number of entries returned */
) {
  ...
}
?>

Backward Incompatible Changes

None.

Proposed PHP Version(s)

Next PHP 8.x (8.6).

RFC Impact

To the Ecosystem

Allowing more local, less redundant and less error-prone documentation of function parameters should enable better documentation. This might impact code style / formatting guidelines and auto formatter configurations and has to be decided in the respective communities.

To Existing Extensions

None.

To SAPIs

None.

Open Issues

None.

Future Scope

None.

Voting Choices

Primary Vote requiring a 2/3 majority to accept the RFC:

Vote: Add DocComment support to function parameters as outlined in the RFC? — Yes: 23 · No: 0 · Abstain: 4 (closed)

Implementation

https://github.com/php/php-src/pull/21279

References

None.

Rejected Features

None.

Changelog

  • 2026-02-21 Initial
  • 2026-02-22 Add link to discussion mailing list thead, remove part about ABI change
  • 2026-02-23 Add implementation PR and test for new function
  • 2026-02-25 Adapt examples to show DocComment before / after parameter