zip extension only acts when closing the archive
Description
The following code:
<?php
$archive = new ZipArchive();
// case 1: $name = '/notexistingfilename'
// case 2: $name = '/notexisting/notexistingfilename'
$res = $archive->open($name, ZipArchive::CREATE);
if ($res !== true) {
// ...........................
}
// ...........
$archive->close();
Resulted in this output:
case 1
ZipArchive::close(): Failure to create temporary file: Permission denied
case 2
ZipArchive::close(): Failure to create temporary file: No such file or directory
But I expected this output instead:
case 1
ZipArchive::open(): Failure to create temporary file: Permission denied
case 2
ZipArchive::open(): Failure to create temporary file: No such file or directory
PHP Version
PHP 8.3.7
Operating System
Fedora 39
It is not a bug but it is quite confusing.
yes ZipArchive::open does not raise an E_WARNING unlike ZipArchive::close. Can't really say if this is the proper behavior/any room for improvements, @nielsdos thoughts ?
This is what is reported by libzip library where everything is done when close is called Probably nothing we can really change on PHP side
Maybe we can improve the documentation; transferring the ticket to doc-en might be in reasonable.
If this comes from libzip, I say: move to docs issue. Anyway, even if we were to add checks at open time, we might run into TOCTOU related issues, so let's not do that.