1--TEST--
2Phar: test edge cases of readfile() function interception
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip");?>
5<?php if (version_compare(PHP_VERSION, "6.0", "!=")) die("skip requires php 6.0 or newer"); ?>
6--INI--
7phar.readonly=0
8--FILE--
9<?php
10Phar::interceptFileFuncs();
11$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
12$pname = 'phar://' . $fname;
13
14chdir(dirname(__FILE__));
15file_put_contents($fname, "blah\n");
16file_put_contents("foob", "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("foob");
24set_include_path("' . addslashes(dirname(__FILE__)) . '");
25readfile("foob", true);
26readfile("./hi", 0, $context);
27readfile("../oops");
28?>
29');
30include $pname . '/foo/hi';
31?>
32===DONE===
33--CLEAN--
34<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
35<?php rmdir(dirname(__FILE__) . '/poo'); ?>
36<?php unlink(dirname(__FILE__) . '/foob'); ?>
37--EXPECTF--
38blah
39<?php
40readfile("foo/" . basename(__FILE__));
41$context = stream_context_create();
42readfile("foob");
43set_include_path("%stests");
44readfile("foob", true);
45readfile("./hi", 0, $context);
46readfile("../oops");
47?>
48test
49test
50<?php
51readfile("foo/" . basename(__FILE__));
52$context = stream_context_create();
53readfile("foob");
54set_include_path("%stests");
55readfile("foob", true);
56readfile("./hi", 0, $context);
57readfile("../oops");
58?>
59
60Warning: readfile(phar://%sreadfile_edgecasesU.phar.php/oops): failed to open stream: phar error: path "oops" is a directory in phar://%sreadfile_edgecasesU.phar.php/foo/hi on line %d
61===DONE===
62