PHP-CLI 5.4 - GOTO替代方案

xZe*_*ero 0 php command-line goto

我正在开发一个PHP-CLI(PHP 5.4+)应用程序,并且我需要分配邪恶的goto.

例:

<?PHP

// I use PHP  League CLImate and I load it here
/*
 *
 * Many lines of different code and output
 *
 */

MAIN_MENU:
// Some checks which will affect menu below
$climate->clear();
$climate->white("1. Eat sandwich");
$climate->white("2. Eat apple");
$input = $climate->white()->input('Lets go and:');
$input->accept([1, 2]);
$option = $input->prompt();
switch ($option) {
    case 1:
        // Eat sandwich and show output
        // Show some more output
        // Pause a bit
        GOTO MAIN_MENU;

    case 2:
        // Eat apple and show output
        // Show some more output
        // Pause a bit
        GOTO MAIN_MENU;
}
Run Code Online (Sandbox Code Playgroud)

我认为我有理由使用邪恶goto.不幸的goto是,从PHP 5.3开始不再存在.有GOTO,但还有其他方法吗?

我需要使用PHP 5.4+,因为PHP 5.4是PHPLeague CLImate支持的最旧版本.
所以,基本上,它为用户提供了一些选项,用户选择一个选项,它完成任务然后它应该返回主菜单.

irc*_*ell 5

为了记录,goto 在5.3 中添加,未删除.

所以它工作得很好,并被许多项目(主要是解析器和状态机)使用.