note 71506 deleted from functions.arguments by bjori

From: Date: Sat, 30 Dec 2006 16:26:19 +0000
Subject: note 71506 deleted from functions.arguments by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121088@lists.php.net to get a copy of this message
Note Submitter: kieran at kieran dot ca ---- In some cases (like object method overloading) I've wanted to pass a variable number of arguments to a function. PHP solves this problem by insisting on passing a single array of arguments, which can be annoying if you already have functions written that expect a certain number of arguments. Example: <? class Someclass { __call($m,$a){ $this->targetFunction($m,implode($a,',')); // doesn't work, with or without quotes } function targetFunction($target,$var,$anotherVar){ .... } } Someclass::target('var','anotherVar'); ?> The only solution I've found is to expect an array of arguments in any function that may be called like this, substituting it with func_get_args() if neccesary like so: <? class Someclass { __call($m,$a){ $this->targetFunction($m,$a); } function targetFunction ( $target, $a ) { if ( !is_array( $a ) ) $a = func_get_args(); ... } } Someclass::target('var','anotherVar'); ?> I hope someone has a better method for this, it gets messy :-( Kieran

« previous php.notes (#121088) next »