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

Havard Eide's Blog:
Countable
Aug 01, 2008 @ 15:23:28

In a new post Havard Eide looks at the creation of a Countable interface that can be used in any application:

Today I will look at the Countable interface, it has a single function that needs to be implemented: count(), by implementing this you can ensure that there is a count() function ready to use on any given class that implements it. The Countable interface is used in other places in the SPL as well: the ArrayIterator and ArrayObject classes implements this interface ( and SqliteResult if present ).

In his code examples he shows simple methods for returning the count() of a property, but notes that the real power of it comes in the ability to manipulate the number returned from the call based on other parameters (or filtering).

tagged: countable interface count spl arrayiterator arrayobject

Link:


Trending Topics: