php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71064 open($string, ZipArchive::OVERWRITE) does not create non-existing archives
Submitted: 2015-12-08 14:56 UTC Modified: 2022-04-26 17:00 UTC
Votes:6
Avg. Score:4.0 ± 0.8
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:2 (33.3%)
From: php at rachuth dot de Assigned: cmb (profile)
Status: Closed Package: Zip Related
PHP Version: 5.6.16 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at rachuth dot de
New email:
PHP Version: OS:

 

 [2015-12-08 14:56 UTC] php at rachuth dot de
Description:
------------
There is an issue with the ZipArchive class' open() method. In previous versions of PHP when the only flag passed to the method was the ZipArchive::OVERWRITE, the method also created non-existing archives.

Since PHP 5.6 the OVERWRITE flag alone cannot create new archives which breaks compatibility.

Test script:
---------------
// Open new archive in cwd based on timestamp 
$zip = new ZipArchive(); 
$open = $zip->open(time() . '.zip', ZipArchive::OVERWRITE); 
echo $open;

Expected result:
----------------
Expected behavior: The new archive is opened as in the previous version.

Actual result:
--------------
In PHP 5.5 an empty archive is opened.
In PHP 5.6 ZipArchive::ER_OPEN error code is returned (cannot open zip file).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-16 19:34 UTC] jkeller at berkeley dot edu
workaround is to use ZipArchive::CREATE | ZipArchive::OVERWRITE instead of ZipArchive::OVERWRITE
 [2015-12-17 05:44 UTC] pajoye@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: pajoye
 [2015-12-17 05:44 UTC] pajoye@php.net
Thanks for the report.

Sorry to have missed this BC.
 [2016-09-05 17:13 UTC] cmb@php.net
Actually, the bundled libzip had been patched in the past due to
bug #47667, and this later has be re-done again[1]. This patch
causes different behavior with the bundled and a system libzip,
so, in my opinion, it is good that we don't patch libzip anymore.
I guess that this difference is the cause of the confusion
regarding several user notes[2].

Considering that the behavioral change is already around for
nearly 2 years (and always has been for system libzip), it might
be best to stick with the current behavior, and update the manual
appropriately.

[1] <https://github.com/php/php-src/commit/b8cdc731>
[2] <http://php.net/manual/en/ziparchive.open.php>
 [2017-10-24 07:38 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: pajoye +Assigned To:
 [2018-05-08 20:36 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2018-05-08 20:36 UTC] cmb@php.net
Since system libzip is actually preferred in the meantime[1], we
won't customize the bundled libzip anymore.  Thus, I'm switching
to doc issue.

[1] <https://github.com/php/php-src/commit/8857161bf2936bb807ac99c991509821bf7f1100#diff-18e07cc7a4680f60b944b30302e4bfa9>
 [2018-05-08 22:00 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=344995
Log: Fix #71064: open($string, ZipArchive::OVERWRITE) does not create non-existing archives

We're taking the wording from the zip_open() documentation[1], and don't
care to document that ZipArchive::OVERWRITE implied ZipArchive::CREATE
in some formerly bundled libzips.

[1] &lt;https://libzip.org/documentation/zip_open.html&gt;
 [2018-05-08 22:00 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2018-05-08 22:00 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=47ef5a87daa67ac1968d435ee5a48d0dc9a38d72
Log: Fix #71064: open($string, ZipArchive::OVERWRITE) does not create non-existing archives
 [2022-04-26 16:48 UTC] lideln at gmail dot com
Am I the only one still having an issue today with PHP 8.1?

My code:

```
$oZip = new \ZipArchive();
if (($err = $oZip->open($sFile, \ZipArchive::OVERWRITE)) !== true)
```

Does not work from time to time. It is NOT a permission issue. I can totally use `touch($sFile)` and it works perfectly.

I fixed this by using:

```
$oZip = new \ZipArchive();
if (($err = $oZip->open($sFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) !== true)
```

And now it seems to work properly.

Feedback appreciated :)

Best,
 [2022-04-26 17:00 UTC] cmb@php.net
> And now it seems to work properly.

Yeah, you're supposed to provide both constants (i.e.
ZipArchive::OVERWRITE does *not* imply ZipArchive::CREATE).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 21:01:28 2024 UTC