Page 1 of 2
PHP equivalent of goto?
Posted: Thu Jun 03, 2004 5:05 am
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
Posted: Thu Jun 03, 2004 5:54 am
by feyd
goto does not exist, because labels don't exist.
Posted: Thu Jun 03, 2004 6:05 am
by dave420
mjseaden - functions have replaced labels and gotos. embrace them!

Posted: Thu Jun 03, 2004 6:10 am
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...

Posted: Thu Jun 03, 2004 6:10 am
by Grim...
Ah... GOSUB... RETURN.
Bring back BASIC!

Posted: Thu Jun 03, 2004 6:20 am
by feyd
have you tried using $_SERVER['REQUEST_URI'] instead?
Posted: Thu Jun 03, 2004 7:05 am
by mjseaden
Thanks Feyd, I'll give it a go
Posted: Thu Jun 03, 2004 7:15 am
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?
Posted: Thu Jun 03, 2004 7:22 am
by mjseaden
Unfortunately my code has already become spaghettified, to a point at which there is now no hope....
Posted: Thu Jun 03, 2004 7:42 am
by magicrobotmonkey
heh - sorry to hear that!
Posted: Thu Jun 03, 2004 7:57 am
by fangorn
O no, reverting back to the "goto"? functions baby!
Posted: Fri Jun 04, 2004 5:23 am
by dave420
mjseaden - just use this:
Code: Select all
global $_SERVER;
echo $_SERVER["REQUEST_URI"];
that'll work as is, no worry about spaghettification

Posted: Fri Jun 04, 2004 5:30 am
by feyd
no need to
$_SERVER is already a superglobal...

Posted: Tue Jun 08, 2004 4:06 am
by dave420
feyd - it's not always guaranteed

Posted: Tue Jun 08, 2004 6:49 am
by launchcode
dave - show us an instance when it isn't then

A Superglobal is as its name implies - global, regardless of scope.