Support calls to functions with variadic parameters#814
Conversation
|
@AJenbo thanks for your PR, do you have the possibility to add a test that failed before this PR and is fixed with this PR? I assign this PR to you, but feel free to say if you need help creating the tests. |
|
Sure, will try and get around to it some time this week. |
|
Oh, I forgot all about this one. I'll try come up with a same that show the issue. |
|
No fair you guys merged another fix for this just a month later, and the didn't even trace down what the cause was 😂 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #814 +/- ##
============================================
- Coverage 92.84% 92.78% -0.06%
- Complexity 1277 1278 +1
============================================
Files 112 112
Lines 3478 3257 -221
============================================
- Hits 3229 3022 -207
+ Misses 249 235 -14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Ok, I added a test, removed the "be quiet" fix, and made this one more explicit as to what it is doing. Hope that makes it good enough to merge :) |
|
Hi, thanks to this I discovered that a parameter can be both variadic and reference 🤯 The test is good as it's what also missed in #818 but I did not succeed to find a case that would explain why we need specific stuff for PHP < 5.6 or why I tried: #973 (min) #974 (isset) By the way I added there a test for variadic+reference but current fixes still don't support it, so we need an other fix for that. class Test
{
public function foo(string $format, mixed &...$values): string
{
$values[1] = 9;
return sprintf($format, ...$values);
}
public function bar()
{
$variadic1 = 1;
$this->print("Text %d", $variadic1, $variadic2);
return $variadic2;
}
}
$t = new Test();
echo $t->bar(); |
|
Without
I think it also better allow you to realize why the count might be higher, rather then just ignoring a case that appears like it should never happen. |
That's also what I believed reading the code but as you can see here it's still producing a violation: #973 (in both PHP <= 5.6 and > 5.6) |
|
@AJenbo can this be updated to be mergable into 3.0.0? |
|
Sure, though there isn't anything BC in it. |
| $parameters = $reflectionFunction->getParameters(); | ||
|
|
||
| return isset($parameters[$argumentPosition]) && $parameters[$argumentPosition]->isPassedByReference(); | ||
| if (version_compare(PHP_VERSION, '5.6', '<') || $reflectionFunction->isVariadic()) { |
There was a problem hiding this comment.
| if (version_compare(PHP_VERSION, '5.6', '<') || $reflectionFunction->isVariadic()) { | |
| if (PHP_VERSION_ID < 50600 || $reflectionFunction->isVariadic()) { |
There was a problem hiding this comment.
Pulling this in to the merge in to 3.x
Type: bugfix
Breaking change: no
Previously this would often fail on usage of sprintf() and other function that takes variadic parameters.