@@ -215,7 +215,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
215215
216216 public static function exportSignature (\ReflectionFunctionAbstract $ function , bool $ withParameterTypes = true , string &$ args = null ): string
217217 {
218- $ hasByRef = false ;
218+ $ byRefIndex = 0 ;
219219 $ args = '' ;
220220 $ param = null ;
221221 $ parameters = [];
@@ -225,16 +225,20 @@ public static function exportSignature(\ReflectionFunctionAbstract $function, bo
225225 .($ param ->isPassedByReference () ? '& ' : '' )
226226 .($ param ->isVariadic () ? '... ' : '' ).'$ ' .$ param ->name
227227 .($ param ->isOptional () && !$ param ->isVariadic () ? ' = ' .self ::exportDefault ($ param ) : '' );
228- $ hasByRef = $ hasByRef || $ param ->isPassedByReference ();
228+ if ($ param ->isPassedByReference ()) {
229+ $ byRefIndex = 1 + $ param ->getPosition ();
230+ }
229231 $ args .= ($ param ->isVariadic () ? '...$ ' : '$ ' ).$ param ->name .', ' ;
230232 }
231233
232- if (!$ param || !$ hasByRef ) {
234+ if (!$ param || !$ byRefIndex ) {
233235 $ args = '...\func_get_args() ' ;
234236 } elseif ($ param ->isVariadic ()) {
235237 $ args = substr ($ args , 0 , -2 );
236238 } else {
237- $ args .= sprintf ('...\array_slice(\func_get_args(), %d) ' , \count ($ parameters ));
239+ $ args = explode (', ' , $ args , 1 + $ byRefIndex );
240+ $ args [$ byRefIndex ] = sprintf ('...\array_slice(\func_get_args(), %d) ' , $ byRefIndex );
241+ $ args = implode (', ' , $ args );
238242 }
239243
240244 $ signature = 'function ' .($ function ->returnsReference () ? '& ' : '' )
0 commit comments