There is a method with an unknown number of arguments in advance, the first and second arguments are required and must have certain values. I want to document this, but I don’t know how:

/** * @param string $name * @param string $type * @param string $param_1-$param_x */ public function some_method() { $args = func_get_args(); } 

Or am I fundamentally wrong, allowing for this method of passing arguments and need to pass a variable number of arguments with an array: some_method($name, $type, array $param) ?

  • Documenting, it is for this, that after reading it was clear what to do with all this. On this and need to focus. If the parameters are required, then it is desirable to indicate them directly in the function declaration as you suggested. And everything else is not so important. - E_p
  • @E_p Well, there are probably questions to my IDE PhpStorm, but he doesn’t like to document the parameters that are not really in the method declaration. - toxxxa

2 answers 2

Starting with PHP 5.6, a new syntax is used for an unknown number of arguments, without using the func_get_args() function. In this case, all the details can be described within the @param directive for the argument ...$args

 /** * @param string $name ... * @param string $type ... * @param mixed $args ... */ public function some_method($name, $type, ...$args) { // foreach($args as $arg) { ... }; } 

    The third argument is an array of strings, as I understood:

     /** * @param string $name * @param string $type * @param string $otherParams... */ public function some_method() { $args = func_get_args(); } 
    • string[] $otherParams... It makes sense when all the other parameters of the string. The php documentation uses mixed . - E_p
    • @E_p, in the question of the vehicle, it seems to be trying to hint that the remaining parameters are strings, so I put an array of strings. - user207618
    • @Other third parameter is not an array, but an unknown number of lines. those. some_method($name, $type, $p1, p2, p3, ...) - toxxxa
    • @toxxxa, and the function signature in the example says that the array. Okay, now fix it. - user207618
    • @Other not, at the end I just asked "there may be unknown parameters bad practice and not to be excreted, but to transfer an array" - toxxxa