Since 2.1.13, when redefining a variadic function the arguments passed to the callable do not match those passed in the original call.
Test case:
<?php
use function Patchwork\redefine;
function foo( $a, ...$args ) {
echo "\$a is " . var_export( $a, true ) . "\n";
echo "\$args are " . var_export( $args, true ) . "\n";
}
foo( 1, 2, 3 );
redefine( 'foo', function ( $a, ...$args ) {
echo "redefined!\n";
echo "\$a is " . var_export( $a, true ) . "\n";
echo "\$args are " . var_export( $args, true ) . "\n";
} );
foo( 4, 5, 6 );
Expected output:
$a is 1
$args are array (
0 => 2,
1 => 3,
)
redefined!
$a is 4
$args are array (
0 => 5,
1 => 6,
)
Actual output:
$a is 1
$args are array (
0 => 2,
1 => 3,
)
redefined!
$a is 4
$args are array (
0 =>
array (
0 => 5,
1 => 6,
),
1 => 6,
)
Notes
It seems to me that Patchwork\CodeManipulation\Actions\Arguments\constructReferenceArray() needs to know that an arg is variadic, so it can be merged into the result instead of being included as-is. Maybe something like
Since 2.1.13, when redefining a variadic function the arguments passed to the callable do not match those passed in the original call.
Test case:
Expected output:
Actual output:
Notes
It seems to me that
Patchwork\CodeManipulation\Actions\Arguments\constructReferenceArray()
needs to know that an arg is variadic, so it can be merged into the result instead of being included as-is. Maybe something like