Page 1 of 1

Strange way to handle functions - why this way?

Posted: Tue Oct 02, 2007 8:26 pm
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?

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

Posted: Tue Oct 02, 2007 9:28 pm
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.

Posted: Tue Oct 02, 2007 9:39 pm
by flycast
Thanks superdezign. I suspected this.

Posted: Wed Oct 03, 2007 9:45 am
by feyd
I have to say, that is a horrible piece of code.