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