A Closer Look At ArrayObject
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:
Making Life Better With The SPL Autoloader
How many of us have seen this example in code we’ve worked on?
< ?php
require '/path/to/lib/DatabaseI.php';
require '/path/to/lib/Database.php';
require '/path/to/lib/Authenticate.php';
require '/path/to/lib/User.php';
require '/path/to/lib/BlogEntry.php';
require '/path/to/lib/Comments.php';
require '/path/to/lib/TemplateLoader.php';
?>
Object oriented programming always leaves you with a headache. What if you could master it instead? Stop struggling with object oriented PHP. Mastering Object Oriented PHP is the answer!
Imagine if you could write clear, compelling code each and every time you sat down to work. You can do this. I'll show you how with The Ten Commandments of Clean Code.
Brandon Savage has been a software developer since 2003. Ever since discovering that he could use software to automate routine tasks, he's been hooked. Brandon is passionate about perfecting the art of software development.