Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variadics to type syntax #40

Closed
mindplay-dk opened this issue Jan 28, 2014 · 8 comments
Closed

Add variadics to type syntax #40

mindplay-dk opened this issue Jan 28, 2014 · 8 comments

Comments

@mindplay-dk
Copy link

Looks like variadics will be supported in PHP 5.6 - the PHP-DOC spec might as well support this from day one.

Many libraries already implement variadics using func_get_args() so there was a need to document these already before native support for variadics - this is already supported by PhpStorm:

/**
 * @param string ...$value as many values as you like
 */
function f() {
    ...
}
@mvriel
Copy link
Member

mvriel commented Mar 29, 2014

I agree, this should be documented in the PHPDoc PSR. Support for variadics have been added to phpDocumentor 2.4

@philsturgeon
Copy link

Winner! Can we close this one?

@mvriel
Copy link
Member

mvriel commented Apr 2, 2014

Unfortunately not yet, it hasn't been described properly in the PSR yet.

@DennisBirkholz
Copy link

What if you expect tuples or triples of values?
The variadic notation plus a check in code handles that, but how to document?
It would be nice if the IDE would the know that I require multiples of 2 or 3 additional parameters.
But I have no great idea how to write that atm ...

@mindplay-dk
Copy link
Author

Hopefully this won't deviate from PHP 5.6 syntax when it gets added to the spec? I am documenting it already using the syntax above, and I have seen others doing it as well - as mentioned, it is already supported in PhpStorm.

@mvriel
Copy link
Member

mvriel commented Sep 6, 2015

The variadics notation has been added or will be added according to the way php had provided these

@mvriel mvriel closed this as completed Sep 6, 2015
@BenMorel
Copy link

@mvriel Still no mention of variadics in PSR-5. What is the suggested syntax for documenting variadics? There is an open discussion in the PHPStorm IDE bug tracker about whether to use brackets notation or not in front of variadics.

@Fleshgrinder
Copy link

Imho no brackets, exactly as the language treats it. Using Foo[] would suggest that you actually need to pass an array of Foos but that is not the case.

#!/usr/bin/env php
<?php

final class Foo {
    public function __toString() {
        return 'foo';
    }
}

/**
 * @param Foo ...$foos
 */
function list_foos(Foo ...$foos) {
    foreach ($foos as $foo) {
        echo "{$foo}\n";
    }
}

list_foos(new Foo(), new Foo(), new Foo(), new Foo());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants