Does the SPL still have any relevance
in the Brave New World of PHP7?
Standard PHP Library
Since PHP 5.3.0
Provides
• DataTypes
• Autoloader
• Interfaces
• Iterators
• Exceptions
• DataStructures
• File Handling
• Miscellaneous Functions
DataTypes
DataTypes
SPL Types
Experimental
Alternative to scalar type hinting
Not included in PHP build by default
Types
Int
Float
String
Bool
Enum
Autoloader
Autoloader
Composer
Phar
Interfaces
Interfaces
Iterator Interfaces
Countable
OuterIterator
RecursiveIterator
SeekableIterator
Pattern Interfaces
SplObserver
SplSubject
Iterators
Iterators
Array/Collection Iterators
File/Folder Iterators
XML Iterators
Filter Iterators
Multiple Iterator
Iterators
Generators
Iterators
Iterators Generators
Iterators
Iterators
Call Time: 0.1447
Memory: 361.05 k
Peak Memory: 397.48 k
Generators
Call Time: 0.0900
Memory: 357.20 k
Peak Memory: 395.33 k
Iterators
Iterators Generators
• Less Userland Code
• Core Iterators are already Tested
• Potentially Slower
• Potentially less memory efficient
• More Userland Code
• Requires Userland Testing
• No Rewind
• Can’t be Extended
Exceptions
Exceptions
BadFunctionCallException
BadMethodCallException
DomainException
InvalidArgumentException
LengthException
LogicException
OutOfBoundsException
OutOfRangeException
OverflowException
RangeException
RuntimeException
UnderflowException
UnexpectedValueException
Exceptions
Exception
LogicException
BadFunctionCallException
BadMethodCallException
DomainException
InvalidArgumentException
LengthException
OutOfRangeException
RuntimeException
OutOfBoundsException
OverflowException
RangeException
UnderflowException
UnexpectedValueException
Data Structures
Data Structures
Fixed Array
Doubly-Linked List
Stack
Queue
Heap
Object Storage
Priority Queue
Data Structures
Fixed Array
0.0000
0.0020
0.0000
0.0018
0.1801
0.1110
0.0506
0.0587
0.0271
0.0425
0.0071
0.0181
0.0311
0.0460
0.0104
0.0237
0.0771
0.0755
0.0388
0.0496
0.1910
0.2167
0.0650
0.0898
141010.14
54692.95
32772.13
15628.48
0
20000
40000
60000
80000
100000
120000
140000
160000
0.0000
0.0500
0.1000
0.1500
0.2000
0.2500
Array
Implementation
SPLFixedArray Array
Implementation
SPLFixedArray
PHP 5.6 PHP 7.1
Fixed Array Performance
Time (s) Initialise Time (s) Set Time (s) Sequential Time (s) Sequential with Key
Time (s) Random Time (s) Pop Memory (kb)
Data Structures
Doubly-Linked List
0.1686
0.3154
0.0443
0.1578
0.0251
0.0323
0.0059
0.0167
0.0325
0.0429
0.0101
0.0219
0.2017
0.1029
0.0621
0.0295
141009.55
93754.86
32772.45
39062.82
0
20000
40000
60000
80000
100000
120000
140000
160000
0.0000
0.0500
0.1000
0.1500
0.2000
0.2500
0.3000
0.3500
Array
Implementation
SplDoublyLinkedList Array
Implementation
SplDoublyLinkedList
PHP 5.6 PHP 7.1
Doubly-Linked List Performance
Push Sequential Sequential with Key Pop Memory (kb)
Data Structures
Stack
7.2992
4.8515
2.1875
2.1342
9.5129
5.0899
2.6314
1.5008
285.05
190.65
68.53
78.72
0
50
100
150
200
250
300
0
1
2
3
4
5
6
7
8
9
10
Array
Implementation
SPLStack Array
Implementation
SPLStack
PHP 5.6 PHP 7.1
Stack Performance
Time (s) Push Time (s) Pop Memory (kb)
Data Structures
Queue
6.831
4.9951
2.3795
2.0713
136.463
5.1467
54.8873
1.4965
529.83
428.15
409.97 418.91
0
100
200
300
400
500
600
0
20
40
60
80
100
120
140
160
Array
Implementation
SPLQueue Array
Implementation
SPLQueue
PHP 5.6 PHP 7.1
Queue Performance
Time (s) Enqueue Time (s) Dequeue Memory (kb)
Data Structures
Heap
0.1063
0.1771
0.0833
0.1131
0.2117
0.1548
0.0937
0.0662
20118.98
15564.69
12017.67
9846.63
0
5000
10000
15000
20000
25000
0
0.05
0.1
0.15
0.2
0.25
Array
Implementation
SPLHeap Array
Implementation
SPLHeap
PHP 5.6 PHP 7.1
Heap Performance
Time (s) Build Time (s) Loop Memory (kb)
Data Structures
Rudi Theunissen’s new PHP7 Datastructures
PECL
Github
https://github.com/php-ds
Blog
https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd
Rudi’s Data Structures
• Stack
• Queue
• Priority Queue
• Sequence (List)
• Vector
• Deque (Double-Ended Queue)
• Map
• Set
Data Structures
Stack
7.2992
4.8515
2.1875
2.1342
2.0604
9.5129
5.0899
2.6314
1.5008
1.5503
285.05
190.65
68.53
78.72
44.49
0
50
100
150
200
250
300
0
1
2
3
4
5
6
7
8
9
10
Array
Implementation
SPLStack Array
Implementation
SPLStack Rudi's DS
PHP 5.6 PHP 7.1
Stack Performance
Time (s) Push Time (s) Pop Memory (kb)
Data Structures
Queue
6.831
4.9951
2.3795
2.0713
2.1444
136.463
5.1467
54.8873
1.4965
1.4391
529.83
428.15
409.97 418.91
372.7
0
100
200
300
400
500
600
0
20
40
60
80
100
120
140
160
Array
Implementation
SPLQueue Array
Implementation
SPLQueue Rudi's DS
PHP 5.6 PHP 7.1
Queue Performance
Time (s) Enqueue Time (s) Dequeue Memory (kb)
Files
Files
SplFileInfo
SplFileObject
SplTempFileObject
Assorted Functions
Assorted Functions
Class Functions:
class_implements()
— Return the interfaces which are implemented by the given class or
interface
class_parents()
— Return the parent classes of the given class
class_uses()
— Return the traits used by the given class
Assorted Functions
Reflection
Assorted Functions
Iterator Functions:
iterator_apply()
— Call a function for every element in an iterator
iterator_count()
— Count the elements in an iterator
iterator_to_array()
— Copy the iterator into an array
Standard PHP Library
Provides
• DataTypes 
• Autoloader 
• Interfaces ?
• Iterators ?
• Exceptions 
• DataStructures ?
• File Handling 
• Miscellaneous Functions ?

Does the SPL still have any relevance in the Brave New World of PHP7?