Handling Standard PHP Library (SPL) changes
The SPL is an extension that contains key classes that implement basic data structures and enhance OOP functionality. It was first introduced in PHP 5 and is now included by default in all PHP installations. Covering the entire SPL is beyond the scope of this book. Instead, in this section, we discuss where significant changes have occurred in the SPL when running PHP 8. In addition, we give you tips and guidance on SPL changes that have the potential to cause your existing applications to stop working.
We start by examining changes to the SplFileObject
class.
Understanding changes to SplFileObject
SplFileObject
is an excellent class that incorporates most of the standalone f*()
functions, such as fgets()
, fread()
, fwrite()
, and so forth, into a single class. SplFileObject ::__construct()
method arguments mirror the arguments provided to the fopen()
function.
The main difference in PHP 8 is that a relatively obscure method, fgetss...