Skip to content

Commit

Permalink
[fixed]eval error with void method (#92)
Browse files Browse the repository at this point in the history
Fixed bug proxy class generation that when method of target class specify void return type
  • Loading branch information
Marico authored and huangzhhui committed Jun 8, 2018
1 parent 36b5d17 commit 9db2301
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/framework/src/Proxy/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ private static function getMethodsTemplate(array $reflectionMethods, string $han
if ($reflectionMethod->isConstructor() || $reflectionMethod->isStatic()) {
continue;
}


// define override methodBody
$methodBody = "{
return \$this->{$handlerPropertyName}->invoke('{$methodName}', func_get_args());
}
";

// the template of parameter
$template .= " public function $methodName (";
$template .= self::getParameterTemplate($reflectionMethod);
Expand All @@ -76,13 +82,14 @@ private static function getMethodsTemplate(array $reflectionMethods, string $han
$returnType = $reflectionMethodReturn->__toString();
$returnType = $returnType === 'self' ? $reflectionMethod->getDeclaringClass()->getName() : $returnType;
$template .= " : $returnType";
// if returnType is void
if ($returnType === 'void') {
$methodBody = str_replace('return ', '', $methodBody);
}
}

// override method
$template .= "{
return \$this->{$handlerPropertyName}->invoke('{$methodName}', func_get_args());
}
";
// append methodBody
$template .= $methodBody;
}

return $template;
Expand Down

0 comments on commit 9db2301

Please sign in to comment.