You cannot go beyond the function that I consider: http://php.net/manual/en/control-structures.goto.php
Direct Quote: This is not a complete unlimited transition. The target label must be in the same file and context, which means that you cannot jump out of a function or method and cannot go into one.
This may be due to php being parsed and jumping out of a function will cause a memory leak or something else because it has never been properly closed. In addition, as everyone said above, in fact, you do not need goto. You can simply return different values ββfrom the function and have a condition for each. Goto is just bad practice for modern coding (acceptable if you are using basic).
Example:
function foo(a) { if (a==1) { return 1; } elseif (a==3) { return 2; } else { return 3; } } switch (foo(4)) { //easily replaceable with elseif chain case 1: echo 'Foo was 1'; break; //These can be functions to other parts of the code case 2: echo 'Foo was 3'; break; case 3: echo 'Foo was not 1 or 3'; }
lemondrop
source share