Skip to content

Type declarations of variadic functions #841

@rbairwell

Description

@rbairwell

Variadic functions where introduced in PHP 5.6 and appear to have been supported by PHPCS since 2014 (see #310 ). However, PHP-7 type declarations of variadic functions are not correctly handled (probably also the case with 5.6 type hints)

http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list shows:

function totalIntervals($unit, DateInterval ...$intervals) {

as an example. However, PHPCS is not happy with any style of commenting. See test file:

<?php /**  * Docblock suggested by PHPStorm.  *  * Expected 1 spaces after parameter type; 0 found  * (Squiz.Commenting.FunctionComment.SpacingAfterParamType)  *  * Expected type hint "DateInterval[] ..."; found  * "DateInterval" for $intervals  * (Squiz.Commenting.FunctionComment.IncorrectTypeHint)  *  * @param string $unit Test.  * @param DateInterval[] ...$intervals Test.  */ function a(string $unit, DateInterval ...$intervals) { }//end a() /**  * Docblock from http://stackoverflow.com/a/22271044/136771 .  * (Doxygen)  *  * Doc comment for parameter "$intervals" missing  * (Squiz.Commenting.FunctionComment.MissingParamTag)  *  * Doc comment for parameter $intervals,... does not match  * actual variable name $intervals  * (Squiz.Commenting.FunctionComment.ParamNameNoMatch)  *  * @param string $unit Test.  * @param DateInterval $intervals,... Test.  */ function b(string $unit, DateInterval ...$intervals) { }//end b() /**  * A different attempt.  *  * Expected type hint "DateInterval ..."; found  * "DateInterval" for $intervals  * Squiz.Commenting.FunctionComment.IncorrectTypeHint)  *  * @param string $unit Test.  * @param DateInterval ... $intervals Test.  */ function c(string $unit, DateInterval ...$intervals) { }//end c() /**  * Docblock from http://stackoverflow.com/a/14513563/136771 .  * (phpDocumentor)  *  * Doc comment for parameter $internals,... does not match  * actual variable name $intervals  * (Squiz.Commenting.FunctionComment.ParamNameNoMatch)  *  * @param string $unit Test.  * @param DateInterval $internals,... Test.  */ function d(string $unit, DateInterval ...$intervals) { }//end d() /**  * Docblock from  * https://github.com/phpDocumentor/phpDocumentor2/issues/629  * and  * https://philsturgeon.uk/php/2013/08/30/potential-variadic-function-syntax-for-php-56/  *  * Expected 1 spaces after parameter type; 0 found  * (Squiz.Commenting.FunctionComment.SpacingAfterParamType)  *  * Doc comment for parameter $internals does not match  * actual variable name $intervals  * (Squiz.Commenting.FunctionComment.ParamNameNoMatch)  *  * Expected type hint "DateInterval ..."; found  * "DateInterval" for $internals  * (Squiz.Commenting.FunctionComment.IncorrectTypeHint)   * @param string $unit Test.  * @param DateInterval ...$internals Test.  */ function e(string $unit, DateInterval ...$intervals) { }//end e()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions