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 "", 23 " ", 24 "\0", 25 array(), 26 27 /* prefix with path separator of a non existing directory*/ 28 "/no/such/file/dir", 29 "php/php" 30 31); 32 33for( $i=0; $i<count($names_arr); $i++ ) { 34 echo "-- Iteration $i --\n"; 35 try { 36 var_dump(file_get_contents($names_arr[$i])); 37 } catch (\TypeError|\ValueError $e) { 38 echo get_class($e) . ': ' . $e->getMessage(), "\n"; 39 } 40} 41 42echo "\n*** Done ***\n"; 43?> 44--EXPECTF-- 45*** Testing file_get_contents() : variation *** 46-- Iteration 0 -- 47 48Warning: file_get_contents(-1): Failed to open stream: No such file or directory in %s on line %d 49bool(false) 50-- Iteration 1 -- 51 52Warning: file_get_contents(1): Failed to open stream: No such file or directory in %s on line %d 53bool(false) 54-- Iteration 2 -- 55ValueError: Path cannot be empty 56-- Iteration 3 -- 57ValueError: Path cannot be empty 58-- Iteration 4 -- 59 60Warning: file_get_contents( ): Failed to open stream: No such file or directory in %s on line %d 61bool(false) 62-- Iteration 5 -- 63ValueError: file_get_contents(): Argument #1 ($filename) must not contain any null bytes 64-- Iteration 6 -- 65TypeError: file_get_contents(): Argument #1 ($filename) must be of type string, array given 66-- Iteration 7 -- 67 68Warning: file_get_contents(/no/such/file/dir): Failed to open stream: No such file or directory in %s on line %d 69bool(false) 70-- Iteration 8 -- 71 72Warning: file_get_contents(php/php): Failed to open stream: No such file or directory in %s on line %d 73bool(false) 74 75*** Done *** 76