2013/8/28 Nikita Popov <nikita....@gmail.com>

> Hi internals!
>
> I'd like to propose an RFC, which adds dedicated syntax for variadic
> functions:
>
>     https://wiki.php.net/rfc/variadics
>
> Basically this allows declaring variadics directly in the function
> signature, rather than fetching the arguments using func_get_args().
> Example:
>
>     public function query($query, ...$params) { /* ... */ }
>
> What are your thoughts on this?
>
>
+1, primarily because it makes the code self-documented.

However, I would like to hilight one shortcoming of variadic functions
(both with the old and with the proposed syntax): There is no way to call a
variadic function unless all the arguments are hard-coded.

I am extenting the example of the RFC:

class MySQL implements DB {
  public function query($query, ...$params) {
    // ...
  }
  public function query_and_log($query, ...$params) {
    // this will not work:
    $result = $this->query( $query, $params );
    log( $query );
    return $result;
  }
}

Not only this does not work, but there is no way to make it work without
modifying the original function. Would it be possible to extend the RFC
with new syntax that could cover cases like that as well? Maybe something
like that:

$result = $this->query( $query, ...$params );


Other than that, the RFC is very welcome.

Lazare INEPOLOGLOU
Ingénieur Logiciel






> Thanks,
> Nikita
>

Reply via email to