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