1--TEST--
2Phar: test edge cases of opendir() function interception
3--EXTENSIONS--
4phar
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9
10Phar::interceptFileFuncs();
11
12$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
13$pname = 'phar://' . $fname;
14
15try {
16    opendir(array());
17} catch (TypeError $e) {
18    echo $e->getMessage(), "\n";
19}
20
21mkdir(__DIR__ . '/opendir_edgecases');
22chdir(__DIR__);
23
24$a = opendir('opendir_edgecases');
25
26$arr = array();
27while (false !== ($b = readdir($a))) {
28    $arr[] = $b;
29}
30sort($arr);
31foreach ($arr as $b) {
32    echo "$b\n";
33}
34
35closedir($a);
36
37file_put_contents($pname . '/foo', '<?php
38$context = stream_context_create();
39$a = opendir(".", $context);
40$res = array();
41while (false !== ($b = readdir($a))) {
42$res[] = $b;
43}
44sort($res);
45foreach ($res as $b) {
46echo "$b\n";
47}
48opendir("oops");
49?>');
50
51include $pname . '/foo';
52
53?>
54--CLEAN--
55<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
56<?php rmdir(__DIR__ . '/opendir_edgecases');
57--EXPECTF--
58opendir(): Argument #1 ($directory) must be of type string, array given
59.
60..
61foo
62
63Warning: opendir(phar://%sopendir_edgecases.phar.php/oops): Failed to open directory: %s in phar://%sopendir_edgecases.phar.php/foo on line %d
64