Page 1 of 1

method parameters

Posted: Mon Jun 18, 2007 11:38 pm
by zyklone
Hello people!

my problem is, i want to initialize a class with an array parameter.

$arr = array('param1', 'param2', 'param3');

i want this $arr to be passed in my class parameter orderly. like this

$myclass = new MyClass($arr); // it doesnt seem to work.


Here is the class:

class MyClass($param1, $param2, $param3)
{

}

thanks for the help!

Posted: Mon Jun 18, 2007 11:49 pm
by feyd
PHP 5 or PHP 4?

Generally I would allow the constructor to support both using func_get_args(), is_array() among others..

Posted: Mon Jun 18, 2007 11:51 pm
by zyklone
feyd wrote:PHP 5 or PHP 4?

Generally I would allow the constructor to support both using func_get_args(), is_array() among others..
i use php5. i have use the func_gets_args() but i cant use it in initializing my class.

Posted: Tue Jun 19, 2007 12:06 am
by feyd
If you're using 5.1.3+ you can use Reflection. You're specifically looking to use newInstanceArgs().

http://www.php.net/language.oop5.reflec ... ctionclass