-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Dedicated syntax for variadic parameters #421
Conversation
RFC can be found here: https://wiki.php.net/rfc/variadics I genuinely find this a good thing, especially for the type hinting. Being able to explicitely indicate that a function is variadic via its signature is way better than looking at documentation or directly by looking at its code. So a big +1 :) |
Is the syntax space sensitive? Same examples have a space after the ellipsis and some do not.
|
@failpunk No, whitespace doesn't matter (as with all of PHP). |
@@ -11,4 +11,4 @@ class test { | |||
echo "Done\n"; | |||
?> | |||
--EXPECTF-- | |||
Fatal error: Method test::__clone() cannot accept any arguments in %s on line %d | |||
Fatal error: Method test::__clone() cannot take arguments in %s on line %d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change I wonder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored some of the magic method implementation checks (and changed the error message doing that), but that turned out to be unnecessary in the end. I now removed the changes to avoid cluttering the diff.
Its good to see function A($x,$y,$z) {
printf("%d,%d,%d",$x,$y,$z);
}
function B(...$vars) {
A(...$vars);
}
function C($no, ...$vars) {
foreach ($vars as &$var) {
$var = $var * $no ;
}
A(...$vars);
}
B(1,2,3); // Expect 1,2,3
C(2,1,2,3); // Expect 2,4,8 Would this work this way or how do you achieve this with current implementation. Secondly can arrays be simple used. eg A(...[1,10,100]); // Expect 1,10,100
//OR
$array = array_reverse(range(1,100))
A(...$array) // Expect 100,99,98 I really this not see clarification of this usage case in the RFC. Can you please clarify ? |
@olekukonko you can always use call_user_func_array() for that. For the last example, I don't even see why would you bother to write A(...[1,10]) if you can just write A(1,10). |
@smalyshev that was just an example .... there is so many use cases for |
@olekukonko All of which, as far as I can see, are covered by call_user_func_array(). |
May be use |
Comment on behalf of nikic at php.net: Has been merged. |
For future reference, commit SHA1 is 0d7a638 |
Implementation for https://wiki.php.net/rfc/variadics RFC.