Skip to content

Commit 374d289

Browse files
[Cache][VarExporter] Fix proxy generation to deal with edgy behaviors of internal classes
1 parent df1f8aa commit 374d289

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ProxyHelper.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)