1--TEST-- 2Test file_get_contents() function : error conditions 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7/* Prototype: string file_get_contents( string $filename{, bool $use_include_path[, 8 * resource $context[, int $offset[, int $maxlen]]]] ) 9 * Description: Reads entire file into a string 10 */ 11 12echo "*** Testing error conditions ***\n"; 13 14$file_path = dirname(__FILE__); 15include($file_path."/file.inc"); 16 17echo "\n-- Testing with Non-existing file --\n"; 18print( file_get_contents("/no/such/file/or/dir") ); 19 20echo "\n-- Testing No.of arguments less than expected --\n"; 21print( file_get_contents() ); 22 23echo "\n-- Testing No.of arguments greater than expected --\n"; 24 25create_files($file_path, 1, "text", 0755, 100, "w", "file", 1, "byte"); 26$file_handle = fopen($file_path."/file_put_contents_error.tmp", "w"); 27print( file_get_contents($file_path."/file1.tmp", false, $file_handle, 1, 2, "extra_argument") ); 28 29echo "\n-- Testing for invalid negative maxlen values --"; 30var_dump( file_get_contents($file_path."/file1.tmp", FALSE, $file_handle, 0, -5) ); 31 32delete_files($file_path, 1); 33fclose($file_handle); 34unlink($file_path."/file_put_contents_error.tmp"); 35 36echo "\n*** Done ***\n"; 37?> 38--CLEAN-- 39<?php 40$file_path = dirname(__FILE__); 41if(file_exists($file_path."/file_put_contents_error.tmp")) { 42 unlink($file_path."/file_put_contents_error.tmp"); 43} 44if(file_exists($file_path."/file_put_contents1.tmp")) { 45 unlink($file_path."/file_put_contents1.tmp"); 46} 47?> 48--EXPECTF-- 49*** Testing error conditions *** 50 51-- Testing with Non-existing file -- 52 53Warning: file_get_contents(/no/such/file/or/dir): failed to open stream: No such file or directory in %s on line %d 54 55-- Testing No.of arguments less than expected -- 56 57Warning: file_get_contents() expects at least 1 parameter, 0 given in %s on line %d 58 59-- Testing No.of arguments greater than expected -- 60 61Warning: file_get_contents() expects at most 5 parameters, 6 given in %s on line %d 62 63-- Testing for invalid negative maxlen values -- 64Warning: file_get_contents(): length must be greater than or equal to zero in %s on line %d 65bool(false) 66 67*** Done *** 68