tags:

views:

55

answers:

3

I'm trying to edit a piece of code written by a development company, which uses the following construct a lot:

$dbcol = grabdata($strSqlB,'','','','','','',2);

Is there really not an easier way to do this? The code is completely unreadable.

I would have thought that the following would work, and work well for readability:

$vars = array("parameter1" => $strSqlB, "parameter7" => 2);
$dbcol = grabdata($vars);

is there anything that needs to be refactored in the function itself to make this work? Is there anything else clever we could do to make this less of a clusterfudge?

+1  A: 

you will have to refactor this part:

function  grabdata($parameter1, $parameter2,$parameter3,$parameter4,$parameter5,$parameter6,$parameter7){

to

function  grabdata($vars){
extract($vars);

these two snippets should do exactly the same IF $vars is like you described in your question

ITroubs
A: 

Refactoring would be necessary as the function would need to reference the parameter array by the appropriate key, rather than by specific parameter variable references. Regarding what you could do to further refactor, I'd have to know more about the function itself.

Daniel Ingraham
+1  A: 

Rebuild your params for accept null.

function grabdata($strSqlB , $param7 , $param1 = null , $param2 = null , ....){
   //Code
}

//Exec
$dbcol = grabdata($strSqlB , $param7);
iJD
This is an english site.
poke
Ok. next time >.<! post in english ¬¬
iJD