Page 1 of 1

Design methods question

Posted: Sun May 22, 2005 1:40 pm
by JB05UK
Hello everyone, this is my first thread in here,
Ive been using PHP to accompany my websites for a few months now, I find myself needing to jump inbetween pieces of code but not like the normal if, else statements can do, an example of what i mean would be a windows NT batch file, like the following:-

Code: Select all

if exist %windir%\somefile.txt goto step1
goto exit

:step1
execute some functions...


:exit
pause
exit
Im looking for the same kind of methods but with PHP code, not sure if this is possible but havent come across it yet, so for example with PHP is it possible to use code which would do something like a windows batch file and skip to a labelled section of code missing out any other pieces.

lol, hope people can understand that,
Thanks for any help.

James

Posted: Sun May 22, 2005 1:46 pm
by timvw
support for goto and labels was once "hacked" into the php source tree... but they decided to remove it again...

what is wrong with regular function calls?

Code: Select all

if (whatever) 
{
  exit();
}

// step 1
...

// terminate
exit();

function exit()
{
  die();
}
but you could probably write that cleaner:

Code: Select all

if( !whatever)
{
    // do step 1 etc...
}
// terminate
exit stuff...

Posted: Sun May 22, 2005 1:58 pm
by JB05UK
Hello, Im not excellent at PHP but i can code it, its just batch file style labels and goto's are much easier to split up the code and keep it tidy when lots of if's and else's are used, it tends to get very busy.


Thanks for the reply.

Posted: Sun May 22, 2005 3:30 pm
by Ambush Commander
Encapsulate the logic in Functions. Ever hear of those?