【问题标题】:PHP - Is it possible to return the return command?PHP - 是否可以返回返回命令?
【发布时间】: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 或为此抛出异常
  • 本地函数与父函数隔离。停止执行父进程的最佳方法是抛出异常,但它需要在父调用中进行管理。

标签: php return


【解决方案1】:

没有,因为在return 之后没有执行任何函数语句。

return return 是一个

PHP 解析错误:语法错误,意外“返回”

documentation中对return的很好解释

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    • 2013-10-22
    • 2017-08-21
    • 2014-01-13
    • 2013-07-04
    • 2018-04-04
    相关资源
    最近更新 更多