title: PHP - associative array as an object
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1869091/convert-array-to-object-php">Convert Array to Object PHP</a>  </p>
  </blockquote>
  
  
  
  <p>I'm creating a simple PHP application and I would like to use <a href="http://en.wikipedia.org/wiki/YAML" rel="noreferrer">YAML</a> files as a data storage. I will get the data as an associative array, with this structure for example:</p>
  
  <pre><code>$user = array('username' =&gt; 'martin', 'md5password' =&gt; '5d41402abc4b2a76b9719d911017c592')
  </code></pre>
  
  <p>However, I would like to extend the associative array with some functions and use the <code>-&gt;</code> operator, so I can write something like this:</p>
  
  <pre><code>$user-&gt;username = 'martin';  // sets $user['username']
  $user-&gt;setPassword('hello'); // writes md5 of 'hello' to $user['md5password']
  $user-&gt;save();               // saves the data back to the file
  </code></pre>
  
  <p>Is there a good way to do this without a class definition?</p>
  
  <p>Basically, I would like to have JavaScript style objects in PHP :)</p>