Avoiding temporary array assignment in PHP

Even though I’ve been developing with PHP for a number of years, I still enjoy discovering new ways of working. Even though the stdClass object is about as basic as you can get, it’s never struck me as being a worthwhile tool. Today, I was storing an associative array of objects in a Zend_Registry. Because PHP’s syntax does not support array accessors on method calls, I had to perform a temporary assignation, as follows:

Because I decided to put a stdClass object into the Zend_Registry, the code reads a little more fluently:

As far as I’m aware, there is no significant penalty for using stdClass, but the results are much nicer.

Tagged with: , ,
Posted in Development

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">