SPL, not a bridge too far
by Michelangelo van Dam on Jun 12, 2009
- 4,553 views
With this presentation I hope to show that using SPL doesn't require a PHD and that it really benefits your application design, maintainability and implements best practices to solve common development...
With this presentation I hope to show that using SPL doesn't require a PHD and that it really benefits your application design, maintainability and implements best practices to solve common development problems.
Accessibility
Categories
Tags
More...Upload Details
Uploaded via SlideShare as Apple Keynote
Usage Rights
Statistics
- Favorites
- 5
- Downloads
- 94
- Comments
- 1
- Embed Views
- Views on SlideShare
- 4,543
- Total Views
- 4,553


ArrayObject is pretty much what it says it is. It acts just like an array, but is an object.
<?php
$myArray = array(
'monkey' => 'bananas',
'rabbit' => 'carrots',
'ogre' => 'onions' );
$arrayObj = new ArrayObject($myArray);
echo count($arrayObj) . '\n'; // 3 because it implements Countable
echo 'Ogres exist ? ' . (array_key_exists('ogre', $arrayObj) ? 'Yes' : 'No') . '\n';
//or
echo 'Ogres exist ? ' . (isset($arrayObj['ogre']) ? 'Yes' : 'No') . '\n'; echo 'Ogres eat ' . $arrayObj['ogre'] . '\n';
$arrayObj->ksort();
//getIterator() gets called implicitly
foreach($arrayObj as $key => $value){
echo $key . ' eats ' . $value . '\n';
}
?>
outputs:
Ogres exist ? Yes
Ogres exist ? Yes
Ogres eat onions
monkey eats bananas
ogre eats onions
rabbit eats carrots
You're right though in regards to documentation. It's seriously lacking, and therefore most of the examples found online don't show what SPL actually does. 2 years ago Reply