@@ -142,15 +142,15 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
142
142
continue ;
143
143
}
144
144
145
- $ signature = self ::exportSignature ($ method );
146
- $ parentCall = $ method ->isAbstract () ? "throw new \BadMethodCallException('Cannot forward abstract method \"{$ method ->class }:: {$ method ->name }() \".') " : "parent:: {$ method ->name }(... \\ func_get_args() ) " ;
145
+ $ signature = self ::exportSignature ($ method, true , $ args );
146
+ $ parentCall = $ method ->isAbstract () ? "throw new \BadMethodCallException('Cannot forward abstract method \"{$ method ->class }:: {$ method ->name }() \".') " : "parent:: {$ method ->name }( { $ args } ) " ;
147
147
148
148
if ($ method ->isStatic ()) {
149
149
$ body = " $ parentCall; " ;
150
150
} elseif (str_ends_with ($ signature , '): never ' ) || str_ends_with ($ signature , '): void ' )) {
151
151
$ body = <<<EOPHP
152
152
if (isset( \$this->lazyObjectState)) {
153
- ( \$this->lazyObjectState->realInstance ??= ( \$this->lazyObjectState->initializer)())-> {$ method ->name }(...\\func_get_args() );
153
+ ( \$this->lazyObjectState->realInstance ??= ( \$this->lazyObjectState->initializer)())-> {$ method ->name }( { $ args } );
154
154
} else {
155
155
{$ parentCall };
156
156
}
@@ -172,7 +172,7 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf
172
172
173
173
$ body = <<<EOPHP
174
174
if (isset( \$this->lazyObjectState)) {
175
- return ( \$this->lazyObjectState->realInstance ??= ( \$this->lazyObjectState->initializer)())-> {$ method ->name }(...\\func_get_args() );
175
+ return ( \$this->lazyObjectState->realInstance ??= ( \$this->lazyObjectState->initializer)())-> {$ method ->name }( { $ args } );
176
176
}
177
177
178
178
return {$ parentCall };
@@ -213,15 +213,28 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
213
213
EOPHP ;
214
214
}
215
215
216
- public static function exportSignature (\ReflectionFunctionAbstract $ function , bool $ withParameterTypes = true ): string
216
+ public static function exportSignature (\ReflectionFunctionAbstract $ function , bool $ withParameterTypes = true , string & $ args = null ): string
217
217
{
218
+ $ hasByRef = false ;
219
+ $ args = '' ;
220
+ $ param = null ;
218
221
$ parameters = [];
219
222
foreach ($ function ->getParameters () as $ param ) {
220
223
$ parameters [] = ($ param ->getAttributes (\SensitiveParameter::class) ? '#[\SensitiveParameter] ' : '' )
221
224
.($ withParameterTypes && $ param ->hasType () ? self ::exportType ($ param ).' ' : '' )
222
225
.($ param ->isPassedByReference () ? '& ' : '' )
223
226
.($ param ->isVariadic () ? '... ' : '' ).'$ ' .$ param ->name
224
227
.($ param ->isOptional () && !$ param ->isVariadic () ? ' = ' .self ::exportDefault ($ param ) : '' );
228
+ $ hasByRef = $ hasByRef || $ param ->isPassedByReference ();
229
+ $ args .= ($ param ->isVariadic () ? '...$ ' : '$ ' ).$ param ->name .', ' ;
230
+ }
231
+
232
+ if (!$ param || !$ hasByRef ) {
233
+ $ args = '...\func_get_args() ' ;
234
+ } elseif ($ param ->isVariadic ()) {
235
+ $ args = substr ($ args , 0 , -2 );
236
+ } else {
237
+ $ args .= sprintf ('...\array_slice(\func_get_args(), %d) ' , \count ($ parameters ));
225
238
}
226
239
227
240
$ signature = 'function ' .($ function ->returnsReference () ? '& ' : '' )
0 commit comments