What are the valid use cases of goto in PHP?

One possible use (that can however be be implemented using other means) is implementation of a finite state machine.


See PHP Architect - GOTO in PHP 5.3: is it Really That Evil?

This article gives a short overview of why GOTO can be useful, why we have it in PHP (since 2004) and why it was/is controversial. The general answer seems to be: GOTO is mostly useless and should be avoided unless in very narrow application spaces (like building a compiler):

One thing is certain: there are some application in which a good developer can put GOTO to good use to produce code that is simpler and more efficient, but they are probably not the kind of mainstream programs that your average developer will be writing; therefore, there is a legitimate concern here that inexperienced programmers will use GOTO to the general detriment of their code.

Also see some of the original newslist discussion/controversy mentioned in the article:

Also see this thorough language agnostic discussion about GOTO considered harmful at C2 Wiki

Tags:

Php

Goto