所以我偶然发现了一些我没有意识到的事情:call_user_func_array
显然中断了代码,但没有回过头来完成它的其余部分!换句话说,它就像 toreturn
或break
调用exit
它的当前函数一样工作,忽略后面的所有代码。
class B {
function bar($arg1, $arg2) {
$result = "$arg1 and $arg2";
echo "Indeed we see '$result'.<br>\n";
return $result;
}
}
class A {
function foo() {
$args = ['apples', 'oranges'];
echo "This line executes.<br>\n"
$result = call_user_func_array(['B', 'bar'], $args);
echo "This line never executes.<br>\n";
echo "Thus we won't be able to use the phrase '$result' within this function.<br>\n";
}
}
我们如何才能返回并完成剩下的部分foo
?