1--TEST-- 2Test readfile() function: error conditions 3--FILE-- 4<?php 5/* Prototype: int readfile ( string $filename [, bool $use_include_path [, resource $context]] ); 6 Description: Outputs a file 7*/ 8 9$context = stream_context_create(); 10 11echo "*** Test readfile(): error conditions ***\n"; 12echo "-- Testing readfile() with unexpected no. of arguments --\n"; 13var_dump( readfile() ); // args < expected 14var_dump( readfile(__FILE__, true, $context, 4) ); // args > expected 15 16echo "\n-- Testing readfile() with invalid arguments --\n"; 17// invalid arguments 18var_dump( readfile(NULL) ); // NULL as $filename 19var_dump( readfile('') ); // empty string as $filename 20var_dump( readfile(false) ); // boolean false as $filename 21var_dump( readfile(__FILE__, false, '') ); // empty string as $context 22var_dump( readfile(__FILE__, true, false) ); // boolean false as $context 23 24echo "\n-- Testing readfile() with non-existent file --\n"; 25$non_existent_file = __DIR__."/non_existent_file.tmp"; 26var_dump( readfile($non_existent_file) ); 27 28echo "Done\n"; 29?> 30--EXPECTF-- 31*** Test readfile(): error conditions *** 32-- Testing readfile() with unexpected no. of arguments -- 33 34Warning: readfile() expects at least 1 parameter, 0 given in %s on line %d 35bool(false) 36 37Warning: readfile() expects at most 3 parameters, 4 given in %s on line %d 38bool(false) 39 40-- Testing readfile() with invalid arguments -- 41 42Warning: readfile(): Filename cannot be empty in %s on line %d 43bool(false) 44 45Warning: readfile(): Filename cannot be empty in %s on line %d 46bool(false) 47 48Warning: readfile(): Filename cannot be empty in %s on line %d 49bool(false) 50 51Warning: readfile() expects parameter 3 to be resource, string given in %s on line %d 52bool(false) 53 54Warning: readfile() expects parameter 3 to be resource, bool given in %s on line %d 55bool(false) 56 57-- Testing readfile() with non-existent file -- 58 59Warning: readfile(%s/non_existent_file.tmp): failed to open stream: %s in %s on line %d 60bool(false) 61Done 62