method parameters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
zyklone
Forum Commoner
Posts: 29
Joined: Tue Nov 28, 2006 10:25 pm

method parameters

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP 5 or PHP 4?

Generally I would allow the constructor to support both using func_get_args(), is_array() among others..
User avatar
zyklone
Forum Commoner
Posts: 29
Joined: Tue Nov 28, 2006 10:25 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
Post Reply