Skip to content

Commit 0587c4b

Browse files
authored
fix: Argument must be passed by reference, value given issue
2 parents 164251b + 91314b0 commit 0587c4b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Core/Intercept/Interceptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private function callParentMethod(?object $subject, array $args): mixed
159159

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

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

165165
/**

src/Core/Transform/WovenClassBuilder.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ private function buildMethods(): array
211211
*/
212212
private function buildMethod(BetterReflectionMethod $refMethod): Method
213213
{
214+
$refMethod = new ReflectionMethod($refMethod);
214215
/** @noinspection PhpUnhandledExceptionInspection */
215216
$method = (new Factory)->fromMethodReflection(
216-
new ReflectionMethod($refMethod),
217+
$refMethod,
217218
);
218219

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

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

234235
// Static methods don't have $this
@@ -262,11 +263,11 @@ private function buildMethod(BetterReflectionMethod $refMethod): Method
262263
* Create an associative array with the parameter name as key and the
263264
* parameter as value.
264265
*
265-
* @param Method $method
266+
* @param ReflectionMethod $method
266267
*
267268
* @return string|null
268269
*/
269-
private function getParametersArray(Method $method): ?string
270+
private function getParametersArray(ReflectionMethod $method): ?string
270271
{
271272
$parameters = $method->getParameters();
272273
if (empty($parameters)) {
@@ -276,7 +277,8 @@ private function getParametersArray(Method $method): ?string
276277
$arguments = [];
277278

278279
foreach ($parameters as $parameter) {
279-
$arguments[] = '\'' . $parameter->getName() . '\' => $' . $parameter->getName();
280+
$isRef = $parameter->isPassedByReference() ? '&' : '';
281+
$arguments[] = '\'' . $parameter->getName() . '\' => ' . $isRef . '$' . $parameter->getName();
280282
}
281283

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

0 commit comments

Comments
 (0)