PHP equivalent of goto?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

PHP equivalent of goto?

Post by mjseaden »

Dear All

I've tried my usual Google lookup of 'PHP <command>', but I can't seem to find anything on 'goto'. Normally in a C++-esque language goto is a standard feature. I need it for my current program!

Can anyone tell me the equivalent?

Many thanks

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

goto does not exist, because labels don't exist.
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

mjseaden - functions have replaced labels and gotos. embrace them! :)
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Trouble is of course, I can't read $REQUEST_URI if I call a function from my code. So it's all bollocks really. Sorry feeling really ratty this morning after receiving a load of buerocratic nonsense through the post from the Inland Revenue... :(
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Ah... GOSUB... RETURN.
Bring back BASIC! :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have you tried using $_SERVER['REQUEST_URI'] instead?
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Thanks Feyd, I'll give it a go
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

or you can pass it to the function i.e.

Code: Select all

<?php

  function whereFrom($uri){
    echo "I came from ".$uri;
  }

 whereFrom($_SERVER['REQUEST_URI'] );
?>
Because, anyways, you don't want spaghetti code do you?
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Unfortunately my code has already become spaghettified, to a point at which there is now no hope....
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

heh - sorry to hear that!
fangorn
Forum Commoner
Posts: 41
Joined: Fri May 21, 2004 9:04 am

Post by fangorn »

O no, reverting back to the "goto"? functions baby!
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

mjseaden - just use this:

Code: Select all

global $_SERVER;

echo $_SERVER["REQUEST_URI"];
that'll work as is, no worry about spaghettification :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no need to

Code: Select all

global $_SERVER;
$_SERVER is already a superglobal... :roll:
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

feyd - it's not always guaranteed :)
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

dave - show us an instance when it isn't then ;) A Superglobal is as its name implies - global, regardless of scope.
Post Reply