1--TEST--
2Phar: test edge cases of readfile() function interception
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip");?>
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9Phar::interceptFileFuncs();
10$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
11$pname = 'phar://' . $fname;
12
13readfile(array());
14chdir(__DIR__);
15file_put_contents($fname, "blah\n");
16file_put_contents("readfile_edgecases.txt", "test\n");
17readfile($fname);
18unlink($fname);
19mkdir($pname . '/oops');
20file_put_contents($pname . '/foo/hi', '<?php
21readfile("foo/" . basename(__FILE__));
22$context = stream_context_create();
23readfile("readfile_edgecases.txt");
24set_include_path("' . addslashes(__DIR__) . '");
25readfile("readfile_edgecases.txt", true);
26readfile("./hi", 0, $context);
27readfile("../oops");
28?>
29');
30include $pname . '/foo/hi';
31?>
32===DONE===
33--CLEAN--
34<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
35<?php unlink(__DIR__ . '/readfile_edgecases.txt'); ?>
36--EXPECTF--
37Warning: readfile() expects parameter 1 to be a valid path, array given in %sreadfile_edgecases.php on line %d
38blah
39<?php
40readfile("foo/" . basename(__FILE__));
41$context = stream_context_create();
42readfile("readfile_edgecases.txt");
43set_include_path("%stests");
44readfile("readfile_edgecases.txt", true);
45readfile("./hi", 0, $context);
46readfile("../oops");
47?>
48test
49test
50<?php
51readfile("foo/" . basename(__FILE__));
52$context = stream_context_create();
53readfile("readfile_edgecases.txt");
54set_include_path("%stests");
55readfile("readfile_edgecases.txt", true);
56readfile("./hi", 0, $context);
57readfile("../oops");
58?>
59
60Warning: readfile(phar://%sreadfile_edgecases.phar.php/oops): failed to open stream: phar error: path "oops" is a directory in phar://%sreadfile_edgecases.phar.php/foo/hi on line %d
61===DONE===
62