xref: /PHP-8.1/ext/zip/tests/oo_getnameindex.phpt (revision 74859783)
1--TEST--
2getNameIndex
3--EXTENSIONS--
4zip
5--FILE--
6<?php
7$dirname = __DIR__ . '/';
8include $dirname . 'utils.inc';
9$file = $dirname . 'oo_getnameindex.zip';
10
11@unlink($file);
12
13$zip = new ZipArchive;
14if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
15    exit('failed');
16}
17
18$zip->addFromString('entry1.txt', 'entry #1');
19$zip->addFromString('entry2.txt', 'entry #2');
20$zip->addFromString('dir/entry2d.txt', 'entry #2');
21
22if (!$zip->status == ZIPARCHIVE::ER_OK) {
23    echo "failed to write zip\n";
24}
25$zip->close();
26
27if (!$zip->open($file)) {
28    exit('failed');
29}
30
31
32var_dump($zip->getNameIndex(0));
33var_dump($zip->getNameIndex(1));
34var_dump($zip->getNameIndex(2));
35var_dump($zip->getNameIndex(3));
36
37$zip->close();
38
39?>
40--EXPECT--
41string(10) "entry1.txt"
42string(10) "entry2.txt"
43string(15) "dir/entry2d.txt"
44bool(false)
45--CLEAN--
46<?php
47unlink(__DIR__ . '/oo_getnameindex.zip');
48?>
49