 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Adam Gotterer's Blog: Building an Object Collection Manager with the Standard PHP Library (SPL)
by Chris Cornutt November 02, 2009 @ 09:17:14
Adam Gotterer has written up a tutorial with his process behind creating an object collection manager with PHP's built-in SPL functionality.
The purpose of a collection is to store objects in an organized manner with specific access rules. We are going to build a collection class using the Standard PHP Library (SPL). Our final product will be capable of iterating, counting and access to objects via array. If you are not familiar with SPL you can find some additional information on the PHP SPL manual site. Unfortunately the manual is somewhat lacking.
He creates an object that implements the ArrayAccess, Countable and Iterator objects to create a "Collection" class to hold his multiple objects inside an"objects" array. He includes some code to test the class and the output as a result.
voice your opinion now!
object collection manager spl tutorial
Brandon Savage's Blog: Making Life Better With The SPL Autoloader
by Chris Cornutt July 24, 2009 @ 10:49:52
Brandon Savage has a new post to his blog today looking at autoloading in your application and how the functionality the Standard PHP Library (SPL) provides can make life simpler.
If you've been in the business for any length of time you'd recognize this because almost every single PHP developer does it at one point or another. Until they learn about SPL's autoload functions, that is.
He talks about the spl_autoload_register function that allows you to define your own custom callback function (not just __autoload) to handle the inclusion of the needed files. He even gives examples of some more complex situations where autoloading like this could come in handy.
voice your opinion now!
spl auoloader tutorial
DevShed: Using Directory Iterators to Build Loader Apps in PHP
by Chris Cornutt July 06, 2009 @ 10:17:11
DevShed finishes off their "loader" series of tutorials today with this eighth part focusing on the use of Directory Iterators.
Here's where the SPL comes in, since it's possible to use a combination of its "spl_autoload_register()" function and its RecursiveDirectoryIterator class to refactor the method in question and make it shorter and tighter. In this final chapter of the series I'm going to improve the loader class developed in the previous one by incorporating some of the aforementioned SPL functions and classes.
They change up their code to use a RecursiveDirectoryIterator inside of their __autoload to remove their custom recursive code.
voice your opinion now!
tutorial autoload recursive iterator directory spl
DevShed: Using the spl_autoload() Functions to Build Loader Apps in PHP
by Chris Cornutt July 03, 2009 @ 08:26:58
In the next to last article of their loader series, DevShed looks at replacing some of the file loading functionality in their examples with functions from the SPL.
As I mentioned before, the Standard PHP library comes bundled with some helpful functions, such as "spl_autoload()," "spl_register_extension()" and "spl_autoload_register()" that allow you to either use a default implementation of the "__autoload()" function, or create a custom one for it.
Their example defines the extensions to use for autoloading and the name of the file/class to pull in. The rest is done automagically.
voice your opinion now!
tutorial autoload spl
Rafael Dohms' Blog: SPL a hidden gem
by Chris Cornutt June 10, 2009 @ 11:19:06
Earlier this month Rafael Dohms posted a new article to his blog looking at a feature of PHP it seems not every developer knows about - the Standard PHP Library (or SPL).
By a show of hands, how many people here ever heard of SPL? How many already used it? Chances are most of you didn't raise your hands, and some might even have a confused look on their faces. Indeed that is the sad reality when it comes to SPL, but What is SPL?
He goes on to look at a few different things the SPL has to offer like autoloader overloading, iterators (with an included list of 21 of them) and the SplFixedArray that can be used to help speed up array access and manipulation.
voice your opinion now!
splfixedarray autoloader iterator spl
Procurios Blog: Syntactic Sugar for MySQLi Results using SPL Iterators
by Chris Cornutt May 15, 2009 @ 11:14:31
From the Procurios blog there's a recent post looking at a method letting you use a foreach on the results from a MySQLi request - SPL Iterators.
Ever wondered why you can't use foreach() on MySQLi Results, and instead have to write less convenient while() loops with fetch_row? Actually, you can use foreach() on MySQLi Results. All it takes is some SPL Iterator magic.
The code examples show how to create an Iterator interface (with rewind, current, key, next and valid methods) to create a ResultIterator class for moving back and forth between the values in the result. This allows you to define the new Iterator object and use the foreach structure like you would a normal result set.
They also show how to bypass this whole problem by using a IteratorAggregate in an extension of the MySQLi interface.
voice your opinion now!
resultset mysqli spl tutorial iterator
Blue Parabola Blog: The SPL Deserves Some Reiteration
by Chris Cornutt February 27, 2009 @ 08:45:35
On the Blue Parabola blog Matthew Turland has written up a post about a PHP something that might need a bit more love - the Standard PHP Library.
If any PHP extension is underrated, it's probably the SPL (Standard PHP Library). From what I can tell without having been involved in its development, its purpose is somewhat similar to the STL. A while back, it was useful mainly for allowing class instances to be iterable and simulate array access. [...] Using the SPL classes actually turned out to be pretty straightforward once you got your hands on a good starting guide or two to help you beat the learning curve.
He mentions a few of the things offered by the SPL like the SplFixedArray/SplFastArray, Iterators, SplDoublyLinkedList, SplStack and SplQueue (among others). He also includes some benchmarks running standard code (like normal arrays) against a SPL counterpart - the SPL side beat the normal side hands down. Check out the full post for all of the numbers and comparison types.
voice your opinion now!
spl standard library iterator array queue list stack benchmark
|
Community Events
Don't see your event here? Let us know!
|