Skip to content

Instantly share code, notes, and snippets.

@johnkary
Created May 11, 2016 03:23
Show Gist options
  • Save johnkary/dfa372cf251bebb6da1a39bfe36014af to your computer and use it in GitHub Desktop.
Save johnkary/dfa372cf251bebb6da1a39bfe36014af to your computer and use it in GitHub Desktop.
How did PHP support variadic arguments before the `...$array` function argument syntax in PHP 5.6?
<?php
function some_old($fn) {
// Must remove $fn to use remaining args as variadic
$variadicArrays = array_slice(func_get_args(), 1);
// $variadicArrays is an "implicit" argument because it's not defined in the signature
var_dump($variadicArrays);
}
function some_new($fn, $someNewParam) {
// Must remove $fn and now $someNewParam before variadic argument placeholder
$variadicArrays = array_slice(func_get_args(), 2);
// In fact, $variadicArrays is an "implicit" argument because it's not defined in the signature
var_dump($variadicArrays);
}
$fn = function ($i) { return $i; };
some_old($fn, ['one'], ['two'], ['three']);
some_new($fn, 'Hello', ['one'], ['two'], ['three']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment