Skip to content

Commit

Permalink
Merge pull request goaop#40 from tampe125/master
Browse files Browse the repository at this point in the history
Double check if a method requires any argument passed by reference
  • Loading branch information
DavertMik committed Oct 8, 2014
2 parents 5a59a03 + 08864bd commit bbb2a54
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/AspectMock/Proxy/InstanceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,33 @@ public function getCallsForMethod($method)
// proxify calls to the methods
public function __call($method, $args)
{
if (method_exists($this->instance, $method)) {
return call_user_func_array([$this->instance, $method], $args);
if (method_exists($this->instance, $method))
{
// Is the method expecting any argument passed by reference?
$passed_args = array();
$reflMethod = new \ReflectionMethod($this->instance, $method);
$params = $reflMethod->getParameters();

for($i = 0; $i < count($params); $i++)
{
if(!isset($args[$i]))
{
break;
}

if($params[$i]->isPassedByReference())
{
$passed_args[] = &$args[$i];
}
else
{
$passed_args[] = $args[$i];
}
}

return call_user_func_array([$this->instance, $method], $passed_args);
}

if (method_exists($this->instance, '__call')) {
return call_user_func([$this->instance, '__call'], $method, $args);
}
Expand Down

0 comments on commit bbb2a54

Please sign in to comment.