xref: /PHP-8.4/ext/spl/tests/bug80724.phpt (revision 24e7299c)
1--TEST--
2Bug #80724 (FOLLOW_SYMLINKS interfering with FilesystemIterator key flags)
3--FILE--
4<?php
5$iterator = new FilesystemIterator(__DIR__, FilesystemIterator::KEY_AS_FILENAME);
6foreach ($iterator as $key => $value) {
7    echo var_dump(hasSeparator($key));
8    break;
9}
10$iterator->rewind();
11echo var_dump(hasSeparator($iterator->key()));
12
13$iterator->setFlags(0);
14echo var_dump(hasSeparator($iterator->key()));
15
16$iterator->setFlags(FilesystemIterator::KEY_AS_FILENAME);
17echo var_dump(hasSeparator($iterator->key()));
18
19$iterator2 = new FilesystemIterator(__DIR__, FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::KEY_AS_FILENAME);
20foreach ($iterator2 as $key => $value) {
21    echo var_dump(hasSeparator($key));
22    break;
23}
24$iterator2->rewind();
25echo var_dump(hasSeparator($iterator2->key()));
26
27$iterator2->setFlags(0);
28echo var_dump(hasSeparator($iterator2->key()));
29
30$iterator2->setFlags(FilesystemIterator::KEY_AS_FILENAME);
31echo var_dump(hasSeparator($iterator2->key()));
32
33function hasSeparator($key) {
34    return str_contains($key, __DIR__ . DIRECTORY_SEPARATOR);
35}
36
37?>
38--EXPECT--
39bool(false)
40bool(false)
41bool(true)
42bool(false)
43bool(false)
44bool(false)
45bool(true)
46bool(false)
47