Skip to content

Commit

Permalink
[Cache][VarExporter] Fix proxy generation to deal with edgy behaviors…
Browse files Browse the repository at this point in the history
… of internal classes
  • Loading branch information
nicolas-grekas committed Oct 13, 2023
1 parent df1f8aa commit 374d289
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ProxyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);

public static function exportSignature(\ReflectionFunctionAbstract $function, bool $withParameterTypes = true, string &$args = null): string
{
$hasByRef = false;
$byRefIndex = 0;
$args = '';
$param = null;
$parameters = [];
Expand All @@ -225,16 +225,20 @@ public static function exportSignature(\ReflectionFunctionAbstract $function, bo
.($param->isPassedByReference() ? '&' : '')
.($param->isVariadic() ? '...' : '').'$'.$param->name
.($param->isOptional() && !$param->isVariadic() ? ' = '.self::exportDefault($param) : '');
$hasByRef = $hasByRef || $param->isPassedByReference();
if ($param->isPassedByReference()) {
$byRefIndex = 1 + $param->getPosition();
}
$args .= ($param->isVariadic() ? '...$' : '$').$param->name.', ';
}

if (!$param || !$hasByRef) {
if (!$param || !$byRefIndex) {
$args = '...\func_get_args()';
} elseif ($param->isVariadic()) {
$args = substr($args, 0, -2);
} else {
$args .= sprintf('...\array_slice(\func_get_args(), %d)', \count($parameters));
$args = explode(', ', $args, 1 + $byRefIndex);
$args[$byRefIndex] = sprintf('...\array_slice(\func_get_args(), %d)', $byRefIndex);
$args = implode(', ', $args);
}

$signature = 'function '.($function->returnsReference() ? '&' : '')
Expand Down

0 comments on commit 374d289

Please sign in to comment.