Strange way to handle functions - why this way?

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

Post Reply
flycast
Forum Commoner
Posts: 37
Joined: Wed Jun 01, 2005 7:33 pm

Strange way to handle functions - why this way?

Post by flycast »

I have some code some one else wrote. They have a functions.php file that has lots of functions defined like this:

Code: Select all

function UnsetAll() { global $FUNCTION_PATH; return include($FUNCTION_PATH.'UnsetAll_func.php'); }
Then in a differennt file called UnsetAll_func.php the have the function:

Code: Select all

global $_POST;

reset($_POST);

//use key as variable variable
while (list($key,$value) = each($_POST)){
  //exclude sess_id
  if ($key != 'sess_id'){
    //must set to global to access
    global ${$key};
    
    ${$key} = '';
    }
  }
I am trying to understand why the function that calls a function. What is the purpose? Why not just call the function directly instead of indirectly?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Strange way to handle functions - why this way?

Post by superdezign »

flycast wrote:I am trying to understand why the function that calls a function. What is the purpose? Why not just call the function directly instead of indirectly?
Sometimes to condense the code, sometimes to simplify the code, or sometimes to make something that can be called from anywhere and only changed in one spot.
flycast
Forum Commoner
Posts: 37
Joined: Wed Jun 01, 2005 7:33 pm

Post by flycast »

Thanks superdezign. I suspected this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I have to say, that is a horrible piece of code.
Post Reply