Goto

The goto operator PHP is a language construct that allows 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 it is not possible to jump out of a function or method, nor to jump into one.

goto is case insensitive.

<?php

  goto a;
  echo 'Foo';

  a:
  echo 'Bar';

?>

Documentation

See also GoTo statement in PHP and Why PHP, goto, and bubblesort, are good, actually.

Related : Goto Labels, Colon, Jump, Control Flow

Related packages : symfony/symfony, yiisoft/yii2

Added in PHP 5.3