PHP set data by var name
<p>I have class</p>

<pre><code>class User extends BaseModel{
     public $id;
     public $name;
}

class BaseModel{
     function __construct($data=null){
          if($data!=null)
          //set $id and $name
     }
}
</code></pre>

<p>I would like to set $id , $name and any other data that extends BaseModel by calling</p>

<pre><code>$test = new User(array('id'=&gt;1,'name'=&gt;'user name'))
</code></pre>

<p>I tried to use </p>

<pre><code>$this-&gt;__set($arrayKey,$arrayValue);
</code></pre>

<p>But i got error : Fatal error: Call to undefined method User::__set()
What am I doing wrong?
Thank you for any help.</p>
