PHP - Stopping the execution of the calling function [closed]

女生的网名这么多〃 提交于 2019-12-01 23:07:00

Return a value and check for it.

function func1()
{
    $result = func2();
    if ($result === 0) return;

    // Your func1 code here
}

function func2()
{
    if ( ... ) return 1;
    else return 0;
}

Checking a return value isn't messy. It's standard practice. You basically have two options:

  • Check return values.
  • Throw an exception in func2. If it's uncaught in func1 it'll bubble up higher and stop execution in both functions.

There is absolutely no way this will work.

Remember: func2() could be called from ANYWHERE, not only func1(). How would you know that it is func1 you are stopping.

Whatever it is that made you think interrupting the calling function would solve the problem - think again, and tell us about the bigger picture for proper advice.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!