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!
method parameters
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
PHP 5 or PHP 4?
Generally I would allow the constructor to support both using func_get_args(), is_array() among others..
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.feyd wrote:PHP 5 or PHP 4?
Generally I would allow the constructor to support both using func_get_args(), is_array() among others..
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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
http://www.php.net/language.oop5.reflec ... ctionclass