There are two already defined variables that you can use in fake code:
$mm_func_args = func_get_args();
$params is array of references to supplied arguments (func_get_args() does not contain refs in PHP5)
You can use SoftMocks::callOriginal(...) for accessing original function/method as well
Example:
class A { public function b($c, &$d) { var_dump($c, $d); } }
SoftMocks::redefineMethod(A::class, 'b', '$e, &$f', '$f = "hello";');
$a = 2;
(new A())->b(1, $a); // nothing is printed here, so we intercepted the call
var_dump($a); // string(5) "hello"
public static redefineMethod ( string $class, string $method, string $functionArgs, string $fakeCode, boolean $strict = true ) | ||
$class | string | |
$method | string | Method of class to be intercepted |
$functionArgs | string | List of argument names |
$fakeCode | string | Code that will be eval'ed instead of function code |
$strict | boolean | If strict=false then method of declaring class will also be mocked |