News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

DevShed:
Collections and Sorting
March 29, 2006 @ 07:58:03

There are features in every language that developers love to have - in PHP, there are some impressive string and array handling functions that some developers would like to carry over. Unfortunately, there are also some bits of functionality that haven't quite made it to PHP yet - namely collections. In other languages, such as Java or C#, these handy containers let you hold objects for use later. PHP lacks this kind of functionality inherently, but this new DevShed article might just have a way around it.

A collection is an object whose primary function is to store a number of like objects. An object called CarCollection may contain any number of Car objects. Collections can traditionally be accessed in the same manner as arrays, which means CarCollection[n] represents a particular Car object. This is true in C#, Java, and more - but not PHP, unfortunately. Since PHP has only recently begun to develop a package of built in objects (the SPL, Standard PHP Library), the ability to support collections in the accepted behavioral sense is very limited.

Their mission is to work with a datatype that PHP does have to simulate this kind of collection handling - arrays. They walk you through the creation of a foundation class, one that simply allows you to get and fetch from the array. Extending that makes it possible to create a customized method for sorting personal data (name).

0 comments voice your opinion now!
collections sorting array non-native objects collections sorting array non-native objects


blog comments powered by Disqus

Similar Posts

Stijn Leenknegt's Blog: [PHP6] function-return-array idea!

Nikita Popov's Blog: Supercolliding a PHP array

IBM developerWorks: Using Service Data Objects to construct XML

Matthew Weir O'Phinney's Blog: Overloading arrays in PHP 5.2.0

Maarten Balliauw's Blog: LINQ for PHP (Language Integrated Query for PHP)


Community Events





Don't see your event here?
Let us know!


language developer framework testing code podcast install series threedevsandamaybe api opinion refactor symfony2 list unittest community interview introduction release laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework