News Feed
Sections




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

SitePoint PHP Blog:
Fun with Array Interfaces
December 09, 2013 @ 10:53:06

On the SitePoint PHP Blog a tutorial has been posted recently about having some fun with array interfaces via some of the functionality provided through the SPL (Standard PHP Library).

As a programmer who works with different languages every day, I find a lot of joy in learning how things are done differently in other languages and seeing if I can do the same in PHP. One thing I liked in particular in Python was how one can emulate features of native data types in custom classes. [...] I thought it would be nice if you could do the same in PHP on an instance of your custom classes and not only arrays. PHP lets us do this with array interfaces.

He illustrates his intent with some basic Python functionality and shows how to use various PHP interfaces to achieve a similar functionality. He talks about SPL interfaces like Countable, ArrayAccess and Iterator to make objects more useful in an array handling environment. His example uses the idea of a set of user's tweets (from Twitter) and shows the implementation of these three interfaces.

0 comments voice your opinion now!
array interface countable arrayaccess iterator tutorial

Link: http://www.sitepoint.com/fun-array-interfaces

blog comments powered by Disqus

Similar Posts

Gonzalo Ayuso's Blog: Real time monitoring PHP applications with websockets and node.js

WebReference.com: XML and PHP Simplified - Formatting XML Documents

Justin Carmony's Blog: Setting Up Nginx & PHP-FPM on Ubuntu 10.04

Zend Developer Zone: Paging Data Sets With PEAR Pager

PHPBuilder.com: PHP Development on the Facebook Platform: Building Your First App


Community Events

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


conference opinion example library podcast introduction php7 performance framework symfony2 series laravel interview application voicesoftheelephpant api release community part2 configure

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