【发布时间】:2019-02-25 09:41:32
【问题描述】:
假设我们有:
function foo() {
bar();
echo "hello stackoverflow, this is my first question, you helped me so many times, I can't even count it, you are great! <3";
}
function bar() {
return;
}
foo();
我知道这很粗鲁,但是否可以让 bar() 返回像 return return; 这样的“返回命令”来告诉 foo() 也立即返回?我知道如果你在bar() 中设置了一个特定的返回值,你可以通过检查foo() 来做到这一点,但是没有某种方式也可以吗?
【问题讨论】:
-
不,那是不可能的。我会避免使用 goto 或为此抛出异常
-
本地函数与父函数隔离。停止执行父进程的最佳方法是抛出异常,但它需要在父调用中进行管理。