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

Rudi Theunissen:
Efficient data structures for PHP 7
Feb 09, 2016 @ 16:49:37

In this recent article over on Medium.com Rudi Theunissen looks at more efficient data structures for PHP 7 and the introduction of a library that wants to help replace some of the current functionality and dependencies on things like arrays.

PHP has one data structure to rule them all. The array is a complex, flexible, master-of-none, hybrid data structure, combining the behaviour of a list and a linked map. But we use it for everything, because PHP is pragmatic.

[...] The recent release of PHP 7 caused a lot of excitement in the PHP community. We couldn't wait to start using the new features and get a taste of the ~2x performance boost. One of the reasons why it runs that much faster is because the array was redesigned. But it’s still the same structure, “optimised for everything; optimised for nothing” with room for improvement.

He starts with a brief mention of some of the current topics around data structures - the SPL functionality, why fixing them would be difficult and, finally, introducing the library that seeks to supersede them. The remainder of the post goes through the pieces of functionality the library offers and explains how each works including videos and graphs of the performance results:

  • Collection
  • Sequence
  • Vector
  • Deque
  • Stack
  • Queue and PriorityQueue
  • Hashable
  • Map
  • Set

He also answers some of the most common questions he's gotten about the library including the level of testing, documentation for the project and why he structured certain elements and features how he did.

tagged: data structure php7 library ds spl optimized video code

Link: https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd#.xg74fpxwg

David Lundgren:
SPL FileObject & LimitIterator
Jun 24, 2015 @ 13:04:24

In the latest post to his site David Lundgren takes a look at two pieces of PHP's SPL libraries - the FileObject and LimitIterator.

Over that last couple of weeks I've come to use the SPL far more than I have in the past. The SplFileObject for reading CSV files is far more convenient than the fgetcsv() function, and associated code needed for a CSV file. Using the LimitIterator allowed me to easily bypass the first row of the CSV, as they were headers and I knew the format of those headers.

He includes an example of using these two to read from a CSV file, processing the header information and each row following. He also gives another example of the LimitIterator handing the results of a database query, reducing the array set down to only the first twelve items. You can find out more about these two handy tools in their SPL documentation, FileObject and LimitIterator, as well as the rest of the SPL if you haven't looked into it before.

tagged: spl standardphplibrary fileobject limititerator csv database results

Link: http://davidscode.com/blog/2015/06/22/spl-fileobject-limititerator/

Three Devs & A Maybe Podcast:
Introduction to the Standard PHP Library (SPL)
Aug 07, 2014 @ 14:44:20

The Three Devs & A Maybe podcast has posted their latest episode (#37) with hosts Michael Budd, Fraser Hart, Lewis Cains and Edd Mann with an introduction to the SPL (Standard PHP Library).

In this weeks show we are discussing all things SPL (Standard PHP Library), used to solve commonly found problems in an OO-PHP manner. After a brief tangent on what each cast member uses for placeholder text/images, we touch upon the key reasons for SPL's development. Following this we highlight a few of the many data-structures (fixed-array, doubly linked-list) and interfaces (countable) available to you. Finally, we wrap up the show with the regular quiz, which you've probably guessed it, is topically about the Standard PHP Library.

Some of the topics mentioned in this latest episode also include:

You can listen to this latest episode either through the in-page player or by downloading the mp3. If you enjoy the episode, consider subscribing to their feed too.

tagged: threedevsandamaybe podcast ep37 introduction spl standardphplibrary

Link: http://threedevsandamaybe.com/posts/introduction-to-the-standard-php-library-spl/

Joshua Thijssen:
SPL Deepdive: RegexIterator
Feb 13, 2014 @ 17:18:55

Joshua Thijssen has posted a deep dive with the RegexIterator to his site today. This iterator is part of the SPL (Standard PHP Library) that is included with PHP. It allows you to filter items based a given regular expression.

If everything goes according to plan (which never is the case), I’ll try and highlight some of the fascinating stuff that can be found inside the SPL. I do a lot of presentations about the SPL, and one of the things I like to tell people is that even though the SPL, – iterators particularly – is a magnificent piece of code that is often underused and misunderstood, it does come with some quirks and glitches that aren’t documented properly. Today, i’ll explain a bit indepth the RegexIterator. This iterator extends the FilterIterator, meaning it can be used to filter out unwanted entries from parent iterators.

He gives a brief example of it in use to filter the results from a DirectoryIterator but quickly gets into the more advanced functionality. He looks at the different "modes" it can operate in: all matches, get matches, match, replace and split. He includes code examples and explanations for each of them, including the resulting output. He also shows how to filter based on the keys instead of values and briefly mentions the "preg_flags" but doesn't get too far into them as they change based on the mode being used.

tagged: spl standardphplibrary regexiterator deepdive tutorial

Link: https://www.adayinthelifeof.nl/2014/02/12/spl-deepdive-regexiterator

Engine Yard Blog:
The Outer Iterator
Jan 13, 2014 @ 17:45:08

On the Engine Yard blog they have a new tutorial posted by Cal Evans looking at an object offered by the Standard PHP Library - the OuterIterator.

When PHP 5 arrived there was great excitement and rejoicing over the new object model. For many of us who struggled through PHP 4′s “Object Based” paradigm, PHP 5 was a ray of sunshine. We were so excited that many of us lost sight of another important addition to PHP 5, the Standard PHP Library (SPL).

Since then, the excitement over the object model has died down. Many authors and speakers have talked about, blogged about, and written about the SPL. However the SPL itself is a very large topic. We are going to narrow our focus down a bit to a subtopic of a specific section of the SPL. This blog post will deal with the OuterIterator. This is an interface defined in the SPL and used by several of the built in iterators.

He goes on to give a brief introduction about what the OuterIterator is and some examples uses for it, including one of the easier to follow - using it with a FilterIterator-based class. He gets into more detail about how the OuterIterator works and includes example snippets to help clarify. His "DwarfPrinter" class extends the FilterIterator and echoes out the names of The Seven Dwarves. He also includes an example of the output showing a more formatted output that follows the nesting and execution of the iterator. He finishes off the post with a list of iterators are useful to pair with the OuterIteator.

tagged: outeriterator tutorial filteriterator standardphplibrary spl

Link: https://blog.engineyard.com/2014/the-outer-iterator

Cal Evans:
The PHP CachingIterator
Dec 20, 2013 @ 16: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.
tagged: cachingiterator behavior fullcache spl example

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

PHPMaster.com:
Data Structures for PHP Devs: Heaps
Jul 23, 2013 @ 16:10:17

PHPMaster.com has posted the third part of their "Data Structures for PHP Devs" series today, this time focusing on heaps. Heaps are a method for organizing a parent/child relationship that makes it easier to work with.

In past couple articles I’ve introduced you to three basic data structures: stack, queue, and tree. In this article I’ll introduce you to another abstract data type that is closely related: heap. Heaps are specialized tree-like data structures which satisfy the heap property – the node value (key) of any parent is always ordered with respect to its child node values across the entire tree.

He starts off by explaining what the different types of heaps are - maxheap, minheap and (a special instance) a Priority Queue. He talks about the operations available to heaps and starts off with a binary maxheap implementation using arrays. He also mentions some of the functionality that the SPL already provides for this sort of thing - SplMaxHeap, SplMinHeap and the SplPriorityQueue.

tagged: data structure heap tutorial series spl priority queue

Link: http://phpmaster.com/data-structures-3

DPCRadio:
Episode #2012-27 - Elizabeth Smith's "SPL in the Wild"
Nov 12, 2012 @ 18:53:38

The Dutch PHP Conference has posted their latest podcast in their DPCRadio series as recorded at this year's Dutch PHP Conference - Elizabeth Smith's SPL in the Wild:

The standard PHP library (SPL) is growing in both maturity and use. But a lot of developers still aren't aware of the tools in SPL or simply haven't seen good examples of how to use the code. From interfaces to an autoload stack to classes that make objects act like arrays, there are tools to make every application leaner and faster, or simply more clever. Using live projects from github, take a look at the good, bad, and the ugly of SPL usage in PHP development.

You can listen to this latest episode either via the in-page player or by downloading it directly. You can also subscribe to their feed and get the latest as they're released.

tagged: dpcradio podcast dpc12 elizabethsmith spl standardphplibrary

Link:

MaltBlue.com:
Painless Data Traversal with PHP FilterIterators
Oct 25, 2012 @ 13:54:35

On the MaltBlue blog Matt Setter has a new post introducing you to using FilterIterators for data traversal:

There’s load of ways to traverse data, especially in PHP where there are a variety of loops available; including while, do while, for and foreach. These are fine for normal structures, such as scalar and associative arrays. But what if you want to get a bit more fancy?

He includes a bit of code showing the typical looping approach that a lot of developers take and how, using a FilterIterator, you can extend the default and make a custom "accept" method to remove certain matching items from the data set.

tagged: filteriterator data traversal filter spl iterator array

Link:

PHPMaster.com:
List Files and Directories with PHP
Oct 23, 2012 @ 13:56:25

On PHPMaster.com there's a new tutorial showing you how to work with files and directories through your PHP applications.

In this article I’ll talk about a common task you might have experienced while developing a PHP application: listing files and directories. I’ll discuss several basic and advanced solutions, each having its pros and cons. First I’ll present three approaches that use some very basic PHP functions and then progress to more robust ones which make use of SPL Iterators.

The solutions they look at are the built-in functions like glob and readdir/opendir as well as SPL iterators up for the task - FilesystemIterator, RecursiveDirectoryIterator and GlobIterator. Code samples are included in the post, showing how to use each method to get and list the files. A few helpful hints are also included to finish off the tutorial (mostly about "tricks" to using the functions effectively).

tagged: tutorial file directory list spl iterator

Link:


Trending Topics: