@@ -395,4 +395,39 @@ public function testGetFunctionArgumentsWithNullValues(): void
395
395
$ this ->assertArrayHasKey ('rest ' , $ result );
396
396
$ this ->assertSame (['extra1 ' , null , 'extra3 ' ], $ result ['rest ' ]);
397
397
}
398
+
399
+ public function testGetFunctionArgumentsWithGapsInBacktraceArrayIndices (): void
400
+ {
401
+ $ options = new Options ([]);
402
+ $ frameBuilder = new FrameBuilder ($ options , new RepresentationSerializer ($ options ));
403
+
404
+ $ testFunction = function (string $ first , int $ second , ...$ rest ) {
405
+ };
406
+
407
+ $ backtraceFrameArgs = [];
408
+ $ backtraceFrameArgs [0 ] = 'hello ' ; // first parameter
409
+ $ backtraceFrameArgs [1 ] = 42 ; // second parameter
410
+ $ backtraceFrameArgs [3 ] = 'extra1 ' ; // gap at index 2, starts variadic args
411
+ $ backtraceFrameArgs [5 ] = 'extra2 ' ; // gap at index 4
412
+ $ backtraceFrameArgs [7 ] = 'extra3 ' ; // gap at index 6
413
+
414
+ $ backtraceFrame = [
415
+ 'function ' => 'testGapsFunction ' ,
416
+ 'args ' => $ backtraceFrameArgs ,
417
+ ];
418
+
419
+ $ reflectionClass = new \ReflectionClass ($ frameBuilder );
420
+ $ getFunctionArgumentValuesMethod = $ reflectionClass ->getMethod ('getFunctionArgumentValues ' );
421
+ $ getFunctionArgumentValuesMethod ->setAccessible (true );
422
+
423
+ $ reflectionFunction = new \ReflectionFunction ($ testFunction );
424
+
425
+ $ result = $ getFunctionArgumentValuesMethod ->invoke ($ frameBuilder , $ reflectionFunction , $ backtraceFrame ['args ' ]);
426
+
427
+ $ this ->assertSame ('hello ' , $ result ['first ' ]);
428
+ $ this ->assertSame (42 , $ result ['second ' ]);
429
+
430
+ $ this ->assertArrayHasKey ('rest ' , $ result );
431
+ $ this ->assertSame (['extra1 ' , 'extra2 ' , 'extra3 ' ], $ result ['rest ' ]);
432
+ }
398
433
}
0 commit comments