...

/

Working with Other Extension Gotchas

Working with Other Extension Gotchas

Learn how to handle the ZIP extension and what the new features introduced in the PHP 8 release are.

PHP 8 introduced a number of other noteworthy changes to several PHP extensions. As we have stressed time and again, it’s extremely important for our future careers as PHP developers to be aware of these changes.

Let’s first have a look at changes to database extensions.

New database extension operating system library requirements

Any developer using MySQL, MariaDB, PostgreSQL, or PHP Data Objects (PDO) needs to be aware of new requirements for supporting operating system libraries. The following table summarizes the new minimum versions required in PHP 8:

PHP 8 Database Library Requirements

Extension

Library

Minimum Vers

PgSQL

libpq

9.1

PDO_PGSQL

libpq

9.1

MySQLi

libmysqlclient

5.1

PDO_MYSQL

libmysqlclient

5.1

As we can see from the preceding table, there are two main library changes. libpq affects both the PostgreSQL extension and the driver for the PDO extension. libmysqlclient is the library used by both the MySQL Improved (MySQLi) extension and the MySQL driver for the PDO extension. It should also be noted that if we are using MariaDB, a popular open-source version of MySQL, the new minimum MySQL library requirement applies to us as well.

Now that we are aware of database extension changes, we next turn our attention to the ZIP extension.

Reviewing changes to the ZIP extension

The ZIP extension is used to programmatically create and manage compressed archive files, leveraging the libzip operating system library. Other compression extensions exist, such as Zlib, bzip2, LZF, PHP Archive Format (phar), and Roshal Archive Compressed (RAR); however, none of the other extensions offers the rich range of functionality offered by the ZIP extension. Also, for the most part, the other extensions are special-purpose and are generally unsuitable for generic ZIP file management.

Let's first have a look at the most notable change to this extension.

Dealing with ZIP extension OOP migration

The biggest change to the ZIP extension is one that presents a potentially massive backwards-compatible code break down the road. As of PHP 8, the procedural API (all procedural functions) has been deprecated! Although this does not affect any code at present, all ZIP extension functions will eventually be removed from the language.

The best practice is to migrate any ZIP extension procedural code over to the OOP API using the ZipArchive class. The following code example illustrates how to migrate from procedural code to object code, opening a test.zip file and producing a list of entries: ...