1--TEST--
2Test file_get_contents() function : variation - obscure filenames
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if (substr(PHP_OS, 0, 3) == 'WIN') {
8    die('skip.. Not valid for Windows');
9}
10?>
11--CONFLICTS--
12obscure_filename
13--FILE--
14<?php
15echo "*** Testing file_get_contents() : variation ***\n";
16/* An array of filenames */
17$names_arr = array(
18  /* Invalid args */
19  -1,
20  TRUE,
21  FALSE,
22  NULL,
23  "",
24  " ",
25  "\0",
26  array(),
27
28  /* prefix with path separator of a non existing directory*/
29  "/no/such/file/dir",
30  "php/php"
31
32);
33
34for( $i=0; $i<count($names_arr); $i++ ) {
35    echo "-- Iteration $i --\n";
36    try {
37        var_dump(file_get_contents($names_arr[$i]));
38    } catch (\TypeError|\ValueError $e) {
39        echo get_class($e) . ': ' . $e->getMessage(), "\n";
40    }
41}
42
43echo "\n*** Done ***\n";
44?>
45--EXPECTF--
46*** Testing file_get_contents() : variation ***
47-- Iteration 0 --
48
49Warning: file_get_contents(-1): Failed to open stream: No such file or directory in %s on line %d
50bool(false)
51-- Iteration 1 --
52
53Warning: file_get_contents(1): Failed to open stream: No such file or directory in %s on line %d
54bool(false)
55-- Iteration 2 --
56ValueError: Path cannot be empty
57-- Iteration 3 --
58ValueError: Path cannot be empty
59-- Iteration 4 --
60ValueError: Path cannot be empty
61-- Iteration 5 --
62
63Warning: file_get_contents( ): Failed to open stream: No such file or directory in %s on line %d
64bool(false)
65-- Iteration 6 --
66ValueError: file_get_contents(): Argument #1 ($filename) must not contain any null bytes
67-- Iteration 7 --
68TypeError: file_get_contents(): Argument #1 ($filename) must be of type string, array given
69-- Iteration 8 --
70
71Warning: file_get_contents(/no/such/file/dir): Failed to open stream: No such file or directory in %s on line %d
72bool(false)
73-- Iteration 9 --
74
75Warning: file_get_contents(php/php): Failed to open stream: No such file or directory in %s on line %d
76bool(false)
77
78*** Done ***
79