1--TEST-- 2Close empty file behavior 3--EXTENSIONS-- 4zip 5--SKIPIF-- 6<?php 7if (version_compare(ZipArchive::LIBZIP_VERSION, '1.10.0', '<')) die('skip libzip < 1.10.0'); 8?> 9--FILE-- 10<?php 11$name = __DIR__ . '/oo_close_empty.zip'; 12 13function run($name, $keep) { 14 copy(__DIR__ . '/test.zip', $name); 15 16 $zip = new ZipArchive(); 17 $zip->open($name, ZIPARCHIVE::CREATE); 18 if ($keep) { 19 echo "\nClose and keep\n"; 20 var_dump($zip->setArchiveFlag(ZipArchive::AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE, 1), $zip->status === ZipArchive::ER_OK); 21 } else { 22 echo "Close and delete\n"; 23 } 24 var_dump($zip->getArchiveFlag(ZipArchive::AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE)); 25 for($i=$zip->numFiles ; $i ;) { 26 $zip->deleteIndex(--$i); 27 } 28 $zip->close(); 29 var_dump(file_exists($name)); 30 } 31run($name, false); 32run($name, true); 33?> 34--CLEAN-- 35<?php 36$name = __DIR__ . '/oo_close_empty.zip'; 37@unlink($name); 38?> 39--EXPECTF-- 40Close and delete 41int(0) 42bool(false) 43 44Close and keep 45bool(true) 46bool(true) 47int(1) 48bool(true) 49