• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
nasty code - varaiable variables varaible paramaters

#1
[eluser]frenzal[/eluser]
this is more of a general php issue rather than CI i guess. What i'm working on is a controller that depending on the page loads certain modules (libraries) and accesses a specific method (in the db as a content part) these content parts get stuck together forming some sort of page. Anyway I found on how to do the whole varaible function thing but I need a nice way to deal with my parameters. Right now i have this

Code:
switch(count($p)){
                            case 1: $function = $this->{$con["module"]}->{$con["function"]}($p[0]); break;
                            case 2: $function = $this->{$con["module"]}->{$con["function"]}($p[0], $p[1]); break;                        
                            case 3: $function = $this->{$con["module"]}->{$con["function"]}($p[0], $p[1], $p[2]); break;                            
                            case 4: $function = $this->{$con["module"]}->{$con["function"]}($p[0], $p[1], $p[2], $p[3]); break;                                                        
                            case 5: $function = $this->{$con["module"]}->{$con["function"]}($p[0], $p[1], $p[2], $p[3], $p[4]);    break;                        
                            case 6: $function = $this->{$con["module"]}->{$con["function"]}($p[0], $p[1], $p[2], $p[3], $p[4], $p[5]); break;
                            default: $function = $this->{$con["module"]}->{$con["function"]}(); break;                                                                        
                        }

Sure it works, but it feels so wrong. The array of parameters ($p) could contain any type or number of parameters depending on the funciton being called, all the parameter values are from the db too. Any suggestions, or generally a better way to deal with this thing?

Cheers


Messages In This Thread
nasty code - varaiable variables varaible paramaters - by El Forum - 03-07-2008, 03:18 PM
nasty code - varaiable variables varaible paramaters - by El Forum - 03-07-2008, 03:33 PM
nasty code - varaiable variables varaible paramaters - by El Forum - 03-07-2008, 03:49 PM
nasty code - varaiable variables varaible paramaters - by El Forum - 03-07-2008, 04:17 PM
nasty code - varaiable variables varaible paramaters - by El Forum - 03-08-2008, 04:34 AM
nasty code - varaiable variables varaible paramaters - by El Forum - 03-08-2008, 06:01 AM
nasty code - varaiable variables varaible paramaters - by El Forum - 03-08-2008, 08:14 AM
nasty code - varaiable variables varaible paramaters - by El Forum - 03-10-2008, 03:20 AM
nasty code - varaiable variables varaible paramaters - by El Forum - 03-10-2008, 03:34 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.