Every once in a while I discover a really cool, really underutilized component in PHP and I just have to write about it. I recently discovered (through my use of Zend Framework) the implementation of the ArrayObject class.
ArrayObject is an object that is designed to behave exactly like an array. If that seems confusing, don’t worry, it’s not. ArrayObject is an object. It follows all the rules of how objects work. But it’s designed to implicitly behave like an array for all intents and purposes, including being used in a foreach loop, and accessing it’s properties just like you would access the values in an array. Consider the following code sample:
Monday, April 26th, 2010 @ 7:00 am |
Comment (12) |
Categories: PHP 5, Technology
Tags: PHP, PHP 5, SPL, ArrayObject
How many of us have seen this example in code we’ve worked on?
Friday, July 24th, 2009 @ 3:00 am |
Comment (13) |
Categories: Best Practices, System Architecture, PHP 5
Tags: SPL, autoloader, PHP 5