xref: /PHP-8.0/ext/phar/tests/fgc_edgecases.phpt (revision 79484b4f)
1--TEST--
2Phar: test edge cases of file_get_contents() function interception
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6?>
7--INI--
8phar.readonly=0
9--FILE--
10<?php
11
12Phar::interceptFileFuncs();
13
14$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
15$pname = 'phar://' . $fname;
16
17try {
18    file_get_contents(array());
19} catch (TypeError $e) {
20    echo $e->getMessage(), "\n";
21}
22chdir(__DIR__);
23file_put_contents($fname, "blah\n");
24file_put_contents("fgc_edgecases.txt", "test\n");
25echo file_get_contents($fname);
26unlink($fname);
27mkdir($pname . '/oops');
28
29file_put_contents($pname . '/foo/hi', '<?php
30echo file_get_contents("foo/" . basename(__FILE__));
31$context = stream_context_create();
32try {
33    file_get_contents("./hi", 0, $context, 0, -1);
34} catch (ValueError $exception) {
35    echo $exception->getMessage() . "\n";
36}
37echo file_get_contents("fgc_edgecases.txt");
38set_include_path("' . addslashes(__DIR__) . '");
39echo file_get_contents("fgc_edgecases.txt", true);
40echo file_get_contents("./hi", 0, $context);
41echo file_get_contents("../oops");
42echo file_get_contents("./hi", 0, $context, 50000);
43echo file_get_contents("./hi");
44echo file_get_contents("./hi", 0, $context, 0, 0);
45?>
46');
47
48include $pname . '/foo/hi';
49
50?>
51--CLEAN--
52<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
53<?php unlink(__DIR__ . '/fgc_edgecases.txt'); ?>
54--EXPECTF--
55file_get_contents(): Argument #1 ($filename) must be of type string, array given
56blah
57<?php
58echo file_get_contents("foo/" . basename(__FILE__));
59$context = stream_context_create();
60try {
61    file_get_contents("./hi", 0, $context, 0, -1);
62} catch (ValueError $exception) {
63    echo $exception->getMessage() . "\n";
64}
65echo file_get_contents("fgc_edgecases.txt");
66set_include_path("%stests");
67echo file_get_contents("fgc_edgecases.txt", true);
68echo file_get_contents("./hi", 0, $context);
69echo file_get_contents("../oops");
70echo file_get_contents("./hi", 0, $context, 50000);
71echo file_get_contents("./hi");
72echo file_get_contents("./hi", 0, $context, 0, 0);
73?>
74file_get_contents(): Argument #5 ($length) must be greater than or equal to 0
75test
76test
77<?php
78echo file_get_contents("foo/" . basename(__FILE__));
79$context = stream_context_create();
80try {
81    file_get_contents("./hi", 0, $context, 0, -1);
82} catch (ValueError $exception) {
83    echo $exception->getMessage() . "\n";
84}
85echo file_get_contents("fgc_edgecases.txt");
86set_include_path("%stests");
87echo file_get_contents("fgc_edgecases.txt", true);
88echo file_get_contents("./hi", 0, $context);
89echo file_get_contents("../oops");
90echo file_get_contents("./hi", 0, $context, 50000);
91echo file_get_contents("./hi");
92echo file_get_contents("./hi", 0, $context, 0, 0);
93?>
94
95Warning: file_get_contents(phar://%sfgc_edgecases.phar.php/oops): Failed to open stream: phar error: path "oops" is a directory in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
96
97Warning: file_get_contents(): Failed to seek to position 50000 in the stream in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
98<?php
99echo file_get_contents("foo/" . basename(__FILE__));
100$context = stream_context_create();
101try {
102    file_get_contents("./hi", 0, $context, 0, -1);
103} catch (ValueError $exception) {
104    echo $exception->getMessage() . "\n";
105}
106echo file_get_contents("fgc_edgecases.txt");
107set_include_path("%stests");
108echo file_get_contents("fgc_edgecases.txt", true);
109echo file_get_contents("./hi", 0, $context);
110echo file_get_contents("../oops");
111echo file_get_contents("./hi", 0, $context, 50000);
112echo file_get_contents("./hi");
113echo file_get_contents("./hi", 0, $context, 0, 0);
114?>
115