Mh...i need this for a class loader. Could you post your class loader? (i do not want to invent the wheel again) Thanks!
--- Gruß CB -----Ursprüngliche Nachricht----- Von: Tom Rogers [mailto:[EMAIL PROTECTED] Gesendet: Dienstag, 4. März 2003 11:49 An: Christian Bartels Cc: [EMAIL PROTECTED] Betreff: Re: [PHP] How to use the fields of an array as individual parameter for a function Hi, Tuesday, March 4, 2003, 7:52:26 PM, you wrote: CB> Hello! CB> I'm new here on the list. I hope you can help me! :) CB> I have a function foo1 which has a parameter $params. In the CB> function i want to pass $params to another function foo2. if $params CB> is an array the elements should be passed to foo2 as individual CB> parameters. Is this possible? How do i do that? CB> Example: CB> function foo1($params) { CB> if (is_array($params)) { CB> $object = new foo2(GET THE ELEMENTS OF $params AS INDIVIDUAL CB> PARAMETERS CB> HERE); CB> } else { CB> $object = new foo2($params); CB> } CB> } CB> So when this is called: CB> foo1(array('blue', 'red', 'green')); CB> In foo1 foo2 should be called like this: CB> foo2('blue', 'red', 'green'); CB> Is this possible? CB> Thanks for any help! CB> (sorry about my english ;-)) CB> --- CB> CB CB> -- CB> PHP General Mailing List (http://www.php.net/) CB> To unsubscribe, visit: http://www.php.net/unsub.php You could use eval, something like this: $num = count($params); $vars = '$subject = new foo2('; if($num > 0) { $i = 0; foreach($params as $var){ $vars .= ($i > 0)? ',':''; $vars .= (is_string($var))? "'".$var."'" : $var; $i ++; } } $vars .= ');'; eval($vars); untested but is similar to something I use as a class loader with unknown number of variables to pass. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php