title: How to create new property dynamically
body: <p>How can I create a property from a given argument inside a object's method?</p>
  
  <pre><code>class Foo{
  
    public function createProperty($var_name, $val){
      // here how can I create a property named "$var_name"
      // that takes $val as value?
  
    }
  
  }
  </code></pre>
  
  <p>And I want to be able to access the property like:</p>
  
  <pre><code>$object = new Foo();
  $object-&gt;createProperty('hello', 'Hiiiiiiiiiiiiiiii');
  
  echo $object-&gt;hello;
  </code></pre>
  
  <p>Also is it possible that I could make the property public/protected/private ? I know that in this case it should be public, but I may want to add some magik methods to get protected properties and stuff :)</p>
  
  <p><hr>
  I think I found a solution:</p>
  
  <pre><code>  protected $user_properties = array();
  
    public function createProperty($var_name, $val){
      $this-&gt;user_properties[$var_name] = $val;
  
    }
  
    public function __get($name){
      if(isset($this-&gt;user_properties[$name])
        return $this-&gt;user_properties[$name];
  
    }
  </code></pre>
  
  <p>do you think it's a good idea?</p>