News Feed
Sections




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

Matt Farina's Blog:
SplFixedArray, An Underutilized PHP Gem
September 09, 2011 @ 10:43:11

Matt Farina has a new post today looking at an "underutilized gem" he's found in the offerings of the Standard PHP Library (SPL) - the SplFixedArray.

Arrays in PHP are not arrays per the typical array data type. Instead, as Matt Butcher recently pointed out arrays in PHP are similar to hashes in other languages. This can be a very important point to know when tracking down bugs in code and to programmers coming to PHP from other languages. But, what if we wanted something like a traditional array data type? Maybe something that preserved numeric order. Enter SplFixedArray.

He gives an example of using the SplFixedArray object versus the normal array variables in a simple PHP snippet showing the preservation of numbering order. He also touches on the memory consumption difference between the two, with the fixed array coming in quite a bit lower than the normal array data type (around 25% based on his basic testing). There are some catches to using it, though including incompatibility with array methods and the fact that it doesn't implement things like Iterator or Countable interfaces.

1 comment voice your opinion now!
splfixedarray array replacement issues performance memory usage


blog comments powered by Disqus

Similar Posts

Evert Pot's Blog: PHP-RPC update 4

Felix Geisendorfer's Blog: PHP 5.2.1 was a evil release - check your server

Ben Ramsey: Introducing Array_column() in PHP 5.5

Christian Schaefer's Blog: Simply iterate over XML with plain PHP using little memory and CPU

Christian Stocker's Blog: php xslcache extension by the New York Times


Community Events





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


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

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