Design methods question

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
JB05UK
Forum Newbie
Posts: 2
Joined: Sun May 22, 2005 1:06 pm

Design methods question

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
JB05UK
Forum Newbie
Posts: 2
Joined: Sun May 22, 2005 1:06 pm

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Encapsulate the logic in Functions. Ever hear of those?
Post Reply