Jump to content

Setting Class Vars


maca134

Recommended Posts

Hey

 

Im trying to set some vars in a class, here is code:

 

class someClass {
    public $var1 = '';
    public $var2 = '';

public function __construct($options)
{
	if (isset($options) && is_array($options))
	{
		foreach ($options as $key => $val)
		{
			$this->$$key = $val;
		}
	}
}
}
$options = array('var1' => 1, 'var2' => 2);
$class = new someClass($options);

 

I know the above is wrong but can someone tell me how to access class vars, like you can access vars with a double dollar sign ($$vars)

 

Thanks in advanced  :D

Link to comment
https://forums.phpfreaks.com/topic/196477-setting-class-vars/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.