Skip to content

Commit

Permalink
fix: Argument must be passed by reference, value given issue
Browse files Browse the repository at this point in the history
  • Loading branch information
denise-kao authored and WalterWoshid committed Sep 4, 2024
1 parent 96d684e commit 4ca9603
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Core/Intercept/Interceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private function callParentMethod(?object $subject, array $args): mixed

$this->unwrapVariadicParameters($parentMethod, $args);

return $parentMethod->invoke($subject, ...array_values($args));
return $parentMethod->invokeArgs($subject, array_values($args));
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Core/Transform/WovenClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ private function buildMethods(): array
*/
private function buildMethod(BetterReflectionMethod $refMethod): Method
{
$refMethod = new ReflectionMethod($refMethod);
/** @noinspection PhpUnhandledExceptionInspection */
$method = (new Factory)->fromMethodReflection(
new ReflectionMethod($refMethod),
$refMethod,
);

$methodName = $refMethod->getName();
Expand All @@ -228,7 +229,7 @@ private function buildMethod(BetterReflectionMethod $refMethod): Method
$return = (string)$method->getReturnType() !== 'void' ? 'return ' : '';

// Add parameters as an array with the parameter name as key
$parametersArray = $this->getParametersArray($method);
$parametersArray = $this->getParametersArray($refMethod);
$parameters = $parametersArray ? ", $parametersArray" : '';

// Static methods don't have $this
Expand Down Expand Up @@ -262,11 +263,11 @@ private function buildMethod(BetterReflectionMethod $refMethod): Method
* Create an associative array with the parameter name as key and the
* parameter as value.
*
* @param Method $method
* @param ReflectionMethod $method
*
* @return string|null
*/
private function getParametersArray(Method $method): ?string
private function getParametersArray(ReflectionMethod $method): ?string
{
$parameters = $method->getParameters();
if (empty($parameters)) {
Expand All @@ -276,7 +277,8 @@ private function getParametersArray(Method $method): ?string
$arguments = [];

foreach ($parameters as $parameter) {
$arguments[] = '\'' . $parameter->getName() . '\' => $' . $parameter->getName();
$isRef = $parameter->isPassedByReference() ? '&' : '';
$arguments[] = '\'' . $parameter->getName() . '\' => ' . $isRef . '$' . $parameter->getName();
}

return '[' . implode(', ', $arguments) . ']';
Expand Down

0 comments on commit 4ca9603

Please sign in to comment.