News Feed
Sections




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

Cal Evans:
The PHP CachingIterator
December 20, 2013 @ 10:19:29

In this new post to his site Cal Evans shares an interesting and seldom mentioned part of the SPL in PHP, the CachingIterator, and an interesting behavior he found with its use.

In the course of writing my next book, "Iterating PHP Iterators", I found something very interesting. I have a short chapter on the CachingIterator. One of the flags in the CachingIterator is FULL_CACHE. It was during my experiments with that, that I found…an anomaly.

He includes a snippet of code showing the behavior that does work, just not exactly as expected. He found that to have the values correctly cached, he had to loop through the entire iterator before trying to use it. He also answers the "just rewind() the iterator" comments with another code snippet showing it with the same behavior as before. His final example is one that does work as expected, unsetting the correct index and replacing the value as requested.

So today I learned, don't use the FULL_CACHE flag on the CachingIterator. I am not sure what the FULL_CACHE flag is supposed to do, but it doesn't seem to do anything useful at the moment. Also, it can screw things up for you.
0 comments voice your opinion now!
cachingiterator behavior fullcache spl example

Link: http://blog.calevans.com/2013/12/19/the-php-cachingiterator/

blog comments powered by Disqus

Similar Posts

PseudoCoder.com: How To Really Use Xdebug To Speed Up Your App

Rafael Dohms' Blog: SPL: a hidden gem

Dave Marshall's Blog: Traits in PHP 5.4 - HelloWorld with Logging Trait

Skaldrom's Blog: Want to create your own progranning language? Lexer & Parser in PHP!

PHPMaster.com: A First Look at React


Community Events

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


interview framework example opinion application part2 project introduction api yii2 composer podcast series php7 community language list laravel testing symfony

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