Re: Goto in PHP
Posted: Fri Jan 09, 2009 6:17 pm
I did not realize that... i feel kinda stupid now
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Well then you would also have to argue that switch() has the same problem -- it was structured programming's last attempt to hiding everything but the last 1% of goto's use. All of the structured constructs are gotos -- but with scope as you rightly point out.pytrin wrote:In my opinion, a GOTO in the traditional sense is reuse without scope. This is dangerous, like using a global, but can be used to solve difficult problems very easily (but not elegantly - in my opinion). I liked though the loop example they had in that discussion volomike linked to, that could be a nice addition.
Is it okay to use switch() instead of if/else if/else control structures? I use switch() all the time and I like how I can layer things like so:arborint wrote:you would also have to argue that switch() has the same problem
Code: Select all
switch(Controller::Action) {
case '/register-candidate':
case '/register-employer':
Controller::Dispatch('Registrations/Register');
break;
case '/':
Controller::Dispatch('Home/Login');
break;
default:
Controller::Dispatch(404);
break;
}The one example I gave is parsers. That is usually given as an a good case for inclusion for goto.pytrin wrote:If someone has a good example, I would love to see it.
But your past experience is not the basis for designing language features.Syntac wrote:I've never ever found a need for goto when writing PHP. I doubt that's going to change.
I use switch occasionally as well. I was just pointing out that it is really just a structured goto -- and a pretty blatant one at that. That is typically why programmers tend to intuitively shy away from using switch().volomike wrote:Is it okay to use switch() instead of if/else if/else control structures? I use switch() all the time and I like how I can layer things like so:
I asked for an example in PHP. As far as I know, PHP is not meant to build language parsers.The one example I gave is parsers. That is usually given as an a good case for inclusion for goto.
The main difference between a switch or if/else and a GOTO, is that those structures can't go back in the code and violate the expected direction of statement evaluation flow - from the first row to the last row. To me that is like going back in time (ie, forbidden. did you see back to the future?I was just pointing out that it is really just a structured goto
How could one be given -- there is no goto in PHP! The example I gave is one for why goto is included in general in languages.pytrin wrote:I asked for an example in PHP.
Again, you may not want to write them. There are certainly parsers for YAML, JSON, etc. done in PHP. The question of whether you or I would write a parser in PHP, or use goto, is separate issue from whether anyone might want to write a parser or whether goto should be included in the language.pytrin wrote:As far as I know, PHP is not meant to build language parsers.
I meant a good example where a GOTO might simplify something in PHP...How could one be given -- there is no goto in PHP! The example I gave is one for why goto is included in general in languages.
I'm not talking about me wanting or not to do something, I'm talking about appropriateness of the feature to the language. PHP was not meant to be a general purpose language, though it can do many things. Asking for a potentially troublesome to implement features the language is not intended for is not a convincing case.Again, you may not want to write them