zip_entry_close()
The zip_entry_close() function is a built-in function in PHP that is used to close a zip_entry handle. When you are done working with a file in a zip archive,
⚠️ Deprecated & Removed: The
zip_*functions (includingzip_entry_close()) were deprecated in PHP 7.4 and removed in PHP 8.0. This content is preserved for legacy reference only. For modern PHP, use theZipArchiveclass instead.
The zip_entry_close() function was a built-in function in PHP used to close a zip_entry handle. When you are done working with a file in a zip archive, you should close the handle using zip_entry_close() to release the associated resource. (Note: The legacy zip extension was primarily read-only, so closing the handle does not save changes to the archive.)
Syntax
The syntax of the zip_entry_close() function is as follows:
Syntax of the zip_entry_close() function in PHP
void zip_entry_close(resource $zip_entry)Where $zip_entry is the zip_entry handle returned by zip_read(). (Note: The resource type hint is legacy; this function no longer exists in PHP 8.0+.)
Usage Examples
Let's take a look at a practical example of using zip_entry_close() in PHP.
Example: Closing a Zip Entry Handle
Suppose you have opened a zip archive using the PHP zip functions and extracted the contents of a file using zip_entry_read(). You should close the zip_entry handle using zip_entry_close() once you're done with it, like this:
Closing a Zip Entry Handle in PHP
$zip = zip_open("example.zip");
if ($zip !== false) {
$zip_entry = zip_read($zip);
if ($zip_entry !== false) {
// do something with the contents of the zip entry
zip_entry_close($zip_entry);
}
zip_close($zip);
}This code opens a zip archive file example.zip using zip_open(), reads the first entry with zip_read(), and (in a real program) would open it with zip_entry_open() and read it with zip_entry_read(). When you are finished, zip_entry_close() closes the zip_entry handle and releases the resource, and finally zip_close() closes the archive itself.
Looping over every entry
In practice you rarely close a single entry by hand. zip_read() returns the next entry on each call and false when there are no more, so a while loop closes each handle as it goes:
$zip = zip_open("example.zip");
if (is_resource($zip)) {
while ($entry = zip_read($zip)) {
zip_entry_open($zip, $entry);
// process the entry, e.g. zip_entry_read($entry, zip_entry_filesize($entry));
zip_entry_close($entry); // free this entry before moving on
}
zip_close($zip);
}Migrating to ZipArchive
Because the zip_* family no longer exists in PHP 8.0+, the example above will throw Call to undefined function on a modern interpreter. The ZipArchive class is the supported replacement. It does not require you to close individual entries at all — you read an entry by name and close() the whole archive once:
<?php
$zip = new ZipArchive();
if ($zip->open("example.zip") === true) {
// read a file directly by its name inside the archive
$contents = $zip->getFromName("readme.txt");
echo $contents;
$zip->close(); // closes the archive; no per-entry close needed
}ZipArchive::close() replaces both zip_entry_close() and zip_close(), and unlike the read-only legacy extension it also commits any changes you made with addFile() or addFromString().
Conclusion
In this article, we reviewed the legacy zip_entry_close() function, its syntax, and how it fits into the zip_open() → zip_read() → zip_entry_close() → zip_close() workflow. As noted, these functions were removed in PHP 8.0. For modern PHP development, migrate to the ZipArchive class, which provides a robust, object-oriented API for creating, reading, and modifying ZIP archives without per-entry handle management.