← All results

FIG proposed PHPDoc: @param / @return as the baseline type contract

Group: FIG and PSR compatibility · Category: fig · File: psr_phpdoc_param_return.php

The proposed PHPDoc standard treats @param and @return as the primary documentation of callable types. Static analyzers in the PHP ecosystem implement that contract by rejecting call/return mismatches against those tags even when native typehints are absent. This group anchors that expectation to the FIG drafts rather than to a single analyzer's docs. References: - references/fig-standards/proposed/phpdoc.md - references/fig-standards/proposed/phpdoc-tags.md

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 Pass
psr_phpdoc_param_return.php:44: Argument 1 ($message) is 42 of type int (value: 42) but \Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() takes string (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/psr_phpdoc_param_return.php:27 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
psr_phpdoc_param_return.php:47: Argument 1 ($message) is encodeMessage('x') of type int but \Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/psr_phpdoc_param_return.php:27 [PhanTypeMismatchArgument]
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Pass reported Lv.4+
psr_phpdoc_param_return.php:44: Call to function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() on a separate line has no effect. [identifier=function.resultUnused] [reported-from-level=4]
psr_phpdoc_param_return.php:44: Parameter #1 $message of function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, int given. [identifier=argument.type] [reported-from-level=5]
psr_phpdoc_param_return.php:47: Call to function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() on a separate line has no effect. [identifier=function.resultUnused] [reported-from-level=4]
psr_phpdoc_param_return.php:47: Parameter #1 $message of function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, int given. [identifier=argument.type] [reported-from-level=5]
With strict-rules
psr_phpdoc_param_return.php:44: Call to function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() on a separate line has no effect. [identifier=function.resultUnused]
psr_phpdoc_param_return.php:44: Parameter #1 $message of function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, int given. [identifier=argument.type]
psr_phpdoc_param_return.php:47: Call to function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() on a separate line has no effect. [identifier=function.resultUnused]
psr_phpdoc_param_return.php:47: Parameter #1 $message of function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, int given. [identifier=argument.type]
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Pass
psr_phpdoc_param_return.php:44: Argument 1 of Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, but 42 provided [InvalidArgument]
psr_phpdoc_param_return.php:47: Argument 1 of Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, but int provided [InvalidArgument]
mago 1.46.0mago 1.46.0 Pass
psr_phpdoc_param_return.php:44: Invalid argument type for argument #1 of `Conformance\Tests\PsrPhpdocParamReturn\encodeMessage`: expected `string`, but found `int(42)`. [invalid-argument]
psr_phpdoc_param_return.php:47: Invalid argument type for argument #1 of `Conformance\Tests\PsrPhpdocParamReturn\encodeMessage`: expected `string`, but found `int`. [invalid-argument]
mir 0.70.1mir 0.70.1 Pass
psr_phpdoc_param_return.php:44: InvalidArgument: Argument $message of encodeMessage() expects 'string', got '42' [MIR0201]
psr_phpdoc_param_return.php:47: InvalidArgument: Argument $message of encodeMessage() expects 'string', got 'int' [MIR0201]
phpantom 0.9.0phpantom_lsp 0.9.0 Pass
psr_phpdoc_param_return.php:44: Argument 1 ($message) expects string, got 42 [type_mismatch_argument]
psr_phpdoc_param_return.php:47: Argument 1 ($message) expects string, got int [type_mismatch_argument]
intelephense 1.18.5intelephense 1.18.5 Pass

No diagnostics reported.

phpy 0.2.0phpy 0.2.0 Pass
psr_phpdoc_param_return.php:44: Argument '1' passed to Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() is expected to be of type string, int given
psr_phpdoc_param_return.php:47: Argument '1' passed to Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() is expected to be of type string, int given
qodana 262.8665.325Qodana 262.8665.325 Pass
psr_phpdoc_param_return.php:44: Parameter '42' type is not compatible with declaration when using strict type matching [PhpParamsInspection]
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Pass
psr_phpdoc_param_return.php:44: Expression evaluated but not used [discardExpr]
psr_phpdoc_param_return.php:47: Expression evaluated but not used [discardExpr]
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Pass
psr_phpdoc_param_return.php:44: argument 42 to encodeMessage() violates declared @param string $message — declared contract violation [phpdoc.param-mismatch]
phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Pass
psr_phpdoc_param_return.php:44: Call to function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() on a separate line has no effect. [identifier=function.resultUnused]
psr_phpdoc_param_return.php:44: Parameter #1 $message of function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, int given. [identifier=argument.type]
psr_phpdoc_param_return.php:47: Call to function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage() on a separate line has no effect. [identifier=function.resultUnused]
psr_phpdoc_param_return.php:47: Parameter #1 $message of function Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, int given. [identifier=argument.type]
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Pass
psr_phpdoc_param_return.php:44: Argument 1 of Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, but 42 provided [InvalidArgument]
psr_phpdoc_param_return.php:47: Argument 1 of Conformance\Tests\PsrPhpdocParamReturn\encodeMessage expects string, but int provided [InvalidArgument]

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PsrPhpdocParamReturn;

/**
 * FIG proposed PHPDoc: `@param` / `@return` as the baseline type contract.
 *
 * The proposed PHPDoc standard treats `@param` and `@return` as the primary
 * documentation of callable types. Static analyzers in the PHP ecosystem
 * implement that contract by rejecting call/return mismatches against those
 * tags even when native typehints are absent.
 *
 * This group anchors that expectation to the FIG drafts rather than to a
 * single analyzer's docs.
 *
 * References:
 * - references/fig-standards/proposed/phpdoc.md
 * - references/fig-standards/proposed/phpdoc-tags.md
 */

/**
 * @param string $message
 * @return int
 */
function encodeMessage($message)
{
    return strlen($message);
}

/**
 * @param int $code
 */
function takesCode($code): void
{
}

takesCode(encodeMessage('hello'));

// @param string rejects int.
// Intelephense type-checks native declarations primarily and often skips
// PHPDoc-only parameters (same gap as phpdoc_basics_param_types).
encodeMessage(42); // E?: int is not accepted by @param string // E<phpstan>: int is not accepted by @param string // E<phpstan-strict>: int is not accepted by @param string // E<psalm>: int is not accepted by @param string // E<mago>: int is not accepted by @param string // E<mir>: int is not accepted by @param string // E<phan>: int is not accepted by @param string // E<noverify>: int is not accepted by @param string

// @return int value is not accepted by @param string.
encodeMessage(encodeMessage('x')); // E?: nested call returns int, not string