Goto¶
The goto operator PHP is a language construct that allows you to perform an unconditional jump in the flow of your code to a specified label.
Goto one of the very controversial features in PHP and has been the subject of much debate due to its potential to create spaghetti code and make code difficult to read and maintain.
Some legit uses of goto in PHP include breaking out of nested loops, implementing state machines, or in some cases for error handling. However, they are rare, and should only considered in last resort.
The target label must be within the same file and context, meaning that you cannot jump out of a function or method, nor can you jump into one.
<?php
goto a;
echo 'Foo';
a:
echo 'Bar';
?>
See also GoTo statement in PHP, Why PHP, goto, and bubblesort, are good, actually
Related : Goto Labels, Colon
Related packages : symfony/symfony, yiisoft/yii2
Added in PHP 5.3