xref: /PHP-8.2/ext/phar/tests/phar_oo_004.phpt (revision c6357b80)
1--TEST--
2Phar and DirectoryIterator
3--EXTENSIONS--
4phar
5--INI--
6phar.require_hash=0
7--FILE--
8<?php
9
10require_once 'files/phar_oo_test.inc';
11
12$it = new DirectoryIterator('phar://'.$fname);
13
14foreach($it as $name => $ent)
15{
16    var_dump($name);
17    var_dump($ent->getFilename());
18    var_dump($ent->isDir());
19    var_dump($ent->isDot());
20}
21
22?>
23===MANUAL===
24<?php
25
26class MyDirectoryIterator extends DirectoryIterator
27{
28    function __construct($dir)
29    {
30        echo __METHOD__ . "\n";
31        parent::__construct($dir);
32    }
33
34    function rewind(): void
35    {
36        echo __METHOD__ . "\n";
37        parent::rewind();
38    }
39
40    function valid(): bool
41    {
42        echo __METHOD__ . "\n";
43        return parent::valid();
44    }
45
46    function key(): mixed
47    {
48        echo __METHOD__ . "\n";
49        return parent::key();
50    }
51
52    function current(): mixed
53    {
54        echo __METHOD__ . "\n";
55        return parent::current();
56    }
57
58    function next(): void
59    {
60        echo __METHOD__ . "\n";
61        parent::next();
62    }
63}
64
65$it = new MyDirectoryIterator('phar://'.$fname);
66
67foreach($it as $name => $ent)
68{
69    var_dump($name);
70    var_dump($ent->getFilename());
71}
72
73?>
74--CLEAN--
75<?php
76unlink(__DIR__ . '/files/phar_oo_004.phar.php');
77__halt_compiler();
78?>
79--EXPECT--
80int(0)
81string(5) "a.php"
82bool(false)
83bool(false)
84int(1)
85string(1) "b"
86bool(true)
87bool(false)
88int(2)
89string(5) "b.php"
90bool(false)
91bool(false)
92int(3)
93string(5) "e.php"
94bool(false)
95bool(false)
96===MANUAL===
97MyDirectoryIterator::__construct
98MyDirectoryIterator::rewind
99MyDirectoryIterator::valid
100MyDirectoryIterator::current
101MyDirectoryIterator::key
102int(0)
103string(5) "a.php"
104MyDirectoryIterator::next
105MyDirectoryIterator::valid
106MyDirectoryIterator::current
107MyDirectoryIterator::key
108int(1)
109string(1) "b"
110MyDirectoryIterator::next
111MyDirectoryIterator::valid
112MyDirectoryIterator::current
113MyDirectoryIterator::key
114int(2)
115string(5) "b.php"
116MyDirectoryIterator::next
117MyDirectoryIterator::valid
118MyDirectoryIterator::current
119MyDirectoryIterator::key
120int(3)
121string(5) "e.php"
122MyDirectoryIterator::next
123MyDirectoryIterator::valid
124