-
-
Notifications
You must be signed in to change notification settings - Fork 152
PHP 5.6: Use variadics and argument unpacking #80
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -335,10 +335,10 @@ public static function compare($left, $right, $len = NULL) | |
| * @param string|array | ||
| * @return string | ||
| */ | ||
| public static function findPrefix($strings) | ||
| public static function findPrefix(...$strings) | ||
| { | ||
| if (!is_array($strings)) { | ||
| $strings = func_get_args(); | ||
| if (is_array($strings[0])) { | ||
| $strings = $strings[0]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not so simple because it changes signature. Previously the signature suggested that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is true, also the name implies one string argument, not an array. In PHP 7 we should pick one and stick with it (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I vote for variadic. Anyone can always unpack array in function call when needed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I vote for variadic because of better type hint
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO scenario
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dg Do the signature would be changed to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is used very rarely, but common usecase is probably
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 The possibility to typehint the value with variadics is good. And the condition above is there just for BC now (it won't make sense anyway once the method gets string typehint).
That makes sense, but is the difference noticeable at runtime? |
||
| } | ||
| $first = array_shift($strings); | ||
| for ($i = 0; $i < strlen($first); $i++) { | ||
|
|
||
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.
Here is
$prev(...)fine.