1--TEST-- 2Test fileatime(), filemtime(), filectime() & touch() functions : error conditions 3--FILE-- 4<?php 5/* 6 Prototype: int fileatime ( string $filename ); 7 Description: Returns the time the file was last accessed, or FALSE 8 in case of an error. The time is returned as a Unix timestamp. 9 10 Prototype: int filemtime ( string $filename ); 11 Description: Returns the time the file was last modified, or FALSE 12 in case of an error. 13 14 Prototype: int filectime ( string $filename ); 15 Description: Returns the time the file was last changed, or FALSE 16 in case of an error. The time is returned as a Unix timestamp. 17 18 Prototype: bool touch ( string $filename [, int $time [, int $atime]] ); 19 Description: Attempts to set the access and modification times of the file 20 named in the filename parameter to the value given in time. 21*/ 22 23echo "*** Testing error conditions ***\n"; 24 25echo "\n-- Testing with Non-existing files --"; 26/* Both invalid arguments */ 27var_dump( fileatime("/no/such/file/or/dir") ); 28var_dump( filemtime("/no/such/file/or/dir") ); 29var_dump( filectime("/no/such/file/or/dir") ); 30var_dump( touch("/no/such/file/or/dir", 10) ); 31 32/* Only one invalid argument */ 33var_dump( fileatime(__FILE__, "string") ); 34var_dump( filemtime(__FILE__, 100) ); 35var_dump( filectime(__FILE__, TRUE) ); 36var_dump( touch(__FILE__, 10, 100, 123) ); 37 38echo "\n-- Testing No.of arguments less than expected --"; 39var_dump( fileatime() ); 40var_dump( filemtime() ); 41var_dump( filectime() ); 42var_dump( touch() ); 43 44echo "\n-- Testing No.of arguments greater than expected --"; 45/* Both invalid arguments */ 46var_dump( fileatime("/no/such/file/or/dir", "string") ); 47var_dump( filemtime("/no/such/file/or/dir", 100) ); 48var_dump( filectime("/no/such/file/or/dir", TRUE) ); 49var_dump( touch("/no/such/file/or/dir", 10, 100, 123) ); 50 51/* Only one invalid argument */ 52var_dump( fileatime(__FILE__, "string") ); 53var_dump( filemtime(__FILE__, 100) ); 54var_dump( filectime(__FILE__, TRUE) ); 55var_dump( touch(__FILE__, 10, 100, 123) ); 56 57echo "\nDone"; 58?> 59--EXPECTF-- 60*** Testing error conditions *** 61 62-- Testing with Non-existing files -- 63Warning: fileatime(): stat failed for /no/such/file/or/dir in %s on line %d 64bool(false) 65 66Warning: filemtime(): stat failed for /no/such/file/or/dir in %s on line %d 67bool(false) 68 69Warning: filectime(): stat failed for /no/such/file/or/dir in %s on line %d 70bool(false) 71 72Warning: touch(): Unable to create file /no/such/file/or/dir because No such file or directory in %s on line %d 73bool(false) 74 75Warning: fileatime() expects exactly 1 parameter, 2 given in %s on line %d 76NULL 77 78Warning: filemtime() expects exactly 1 parameter, 2 given in %s on line %d 79NULL 80 81Warning: filectime() expects exactly 1 parameter, 2 given in %s on line %d 82NULL 83 84Warning: touch() expects at most 3 parameters, 4 given in %s on line %d 85NULL 86 87-- Testing No.of arguments less than expected -- 88Warning: fileatime() expects exactly 1 parameter, 0 given in %s on line %d 89NULL 90 91Warning: filemtime() expects exactly 1 parameter, 0 given in %s on line %d 92NULL 93 94Warning: filectime() expects exactly 1 parameter, 0 given in %s on line %d 95NULL 96 97Warning: touch() expects at least 1 parameter, 0 given in %s on line %d 98NULL 99 100-- Testing No.of arguments greater than expected -- 101Warning: fileatime() expects exactly 1 parameter, 2 given in %s on line %d 102NULL 103 104Warning: filemtime() expects exactly 1 parameter, 2 given in %s on line %d 105NULL 106 107Warning: filectime() expects exactly 1 parameter, 2 given in %s on line %d 108NULL 109 110Warning: touch() expects at most 3 parameters, 4 given in %s on line %d 111NULL 112 113Warning: fileatime() expects exactly 1 parameter, 2 given in %s on line %d 114NULL 115 116Warning: filemtime() expects exactly 1 parameter, 2 given in %s on line %d 117NULL 118 119Warning: filectime() expects exactly 1 parameter, 2 given in %s on line %d 120NULL 121 122Warning: touch() expects at most 3 parameters, 4 given in %s on line %d 123NULL 124 125Done 126 127