In PHP, zip_close() closes a ZIP archive that was opened with the old procedural zip_open() function.
It is deprecated as of PHP 8.0. For new code, use the ZipArchive class and call $zip->close(), which also saves any changes you made while the archive was open.
Syntax
Call zip_close() with the values you need. Start with this line.
PHP
// Deprecated (PHP 8.0+)
$zip = zip_open('archive.zip');
zip_close($zip);
// Modern equivalent
$zip = new ZipArchive();
$zip->open('archive.zip');
$zip->close();
Call
What it does
zip_close($zip)
Deprecated: closes the resource returned by zip_open() and frees it.
@zip_close($zip)
Deprecated: the @ operator hides the E_DEPRECATED notice, but the function is still old.
$zip->close()
Modern ZipArchive: closes the archive, writes pending changes, and returns true or false.
zip_close() is deprecated in PHP 8.0. It only closes read handles from zip_open(). ZipArchive::close() can both read and write archives, so it is the one to learn first.
Library declarations
PHP
zip_close(resource $zip): void
Parameters
Parameter
Description
zip
Required. The ZIP resource returned by zip_open(). In ZipArchive you call close() on the object instead.
Return Value
Return Value
Description
void
zip_close() returns nothing. ZipArchive::close() returns true on success and false on failure.
PHP Examples
Example 1 — Close a ZipArchive After Writing
Create a small archive in the temp folder, close it, reopen it, and clean up. The old zip_close() call is shown as a comment.
Write buildArchive() that opens a ZipArchive and checks the open result.
Add every file inside try and read numFiles.
Call close() in finally so it always runs.
Print the count, check the file size, and unlink the temp archive.
Frequently Asked Questions
Yes. The procedural zip_* functions are deprecated as of PHP 8.0. Use ZipArchive and its close() method instead.
Call $zip->close() on your ZipArchive object. It returns true on success and also writes any added or changed entries to disk.
PHP closes it when the object is destroyed, but relying on that is risky. Call close() yourself so you can check the result and be sure changes are saved.
No, it returns void. ZipArchive::close() returns a bool, which is handy for error checks.
ZipArchive does not write archives that contain zero entries. Add at least one file or folder before calling close().