diff --git a/language/control-structures/goto.xml b/language/control-structures/goto.xml index 773a82dfe3..68f930ce53 100644 --- a/language/control-structures/goto.xml +++ b/language/control-structures/goto.xml @@ -1,5 +1,5 @@ - + <literal>goto</literal> @@ -7,7 +7,13 @@ The goto operator can be used to jump to another section in the program. The target point is specified by a label followed by a colon, and the instruction is given as - goto followed by the desired target label. + goto followed by the desired target label. This + is not a full unrestricted goto. The target + label must be within the same context, meaning that you cannot jump + out of a function or method, nor can you jump into one. You also + cannot jump into any sort of loop or switch structure. You may jump + out of these, and a common use is to use a goto + in place of a multi-level break. @@ -27,6 +33,56 @@ echo 'Bar'; + + + + + + <literal>goto</literal> loop example + + +]]> + + &example.outputs; + + + + + + + + This will not work + + +]]> + + &example.outputs; + + @@ -36,12 +92,6 @@ Bar The goto operator is available as of PHP 5.3. - - - It is not allowed to jump into a loop or switch statement. A fatal - error is issued in such cases. - -