Improved types for RunnerConfig.php#1071
Conversation
|
Why not set the default to empty array as you originally suggested? |
|
Because I found a solution not breaking B/C. |
|
Is it a B/C break? Passing NULL would have resulted in a crash? |
|
Seems I'm confused a bit. Let's see what we have. Initial method (from master branch): phpbench/lib/Benchmark/RunnerConfig.php Lines 145 to 148 in a2c16ca And if I call $myConfig = RunnerConfig::create();
$myConfig->getIterations(); // Uncaught TypeError: PhpBench\Benchmark\RunnerConfig::getIterations(): Return value must be of type array, null returnedIn #1069 I suggested this solution: public function getIterations(array $default = []): array
{
return $this->iterations ?: $default;
}But it's breaks B/C as some user can have the following code: $myConfig = RunnerConfig::create();
$myConfig->getIterations(null); // Uncaught TypeError: PhpBench\Benchmark\RunnerConfig::getIterations(): Argument #1 ($default) must be of type array, null givenSo to keep B/C we must not change method signature. In this PR we just check the value of phpbench/lib/Benchmark/RunnerConfig.php Lines 107 to 112 in 603f3de As you see the signature is not changed in comparing with master branch. And this code will $myConfig = RunnerConfig::create();
$myConfig->getIterations();
$myConfig->getIterations(null);On the other hand, users couldn't have the code like this as they would get TypeError. So in theory we can consider this case as a bug and use the solution from #1069. What do you think? |
|
yes, I think B/C is only if they could depend on this behavor, in theory they could depend on the runtime error, but that would be truly horrifying (insert XKCD here). It's a bug fix 👍 |
603f3de to
964686d
Compare
|
Fixed:) |
|
thanks! |
No description provided.