1--TEST-- 2Test flock() function: Error conditions 3--CONFLICTS-- 4obscure_filename 5--FILE-- 6<?php 7/* 8Prototype: bool flock(resource $handle, int $operation [, int &$wouldblock]); 9Description: PHP supports a portable way of locking complete files 10 in an advisory way 11*/ 12 13echo "*** Testing error conditions ***\n"; 14 15$file = preg_replace("~\.phpt?$~", '.tmp', __FILE__); 16$fp = fopen($file, "w"); 17 18/* array of operatons */ 19$operations = array( 20 0, 21 LOCK_NB, 22 FALSE, 23 NULL, 24 array(1,2,3), 25 array(), 26 "string", 27 "", 28 "\0" 29); 30 31$i = 0; 32foreach($operations as $operation) { 33 echo "\n--- Iteration $i ---"; 34 var_dump(flock($fp, $operation)); 35 $i++; 36} 37 38 39/* Invalid arguments */ 40$fp = fopen($file, "w"); 41fclose($fp); 42var_dump(flock($fp, LOCK_SH|LOCK_NB)); 43 44var_dump(flock("", "", $var)); 45 46/* No.of args leass than expected */ 47var_dump(flock()); 48var_dump(flock($fp)); 49 50/* No.of args greater than expected */ 51var_dump(flock($fp, "", $var, "")); 52?> 53--CLEAN-- 54<?php 55$file = __DIR__."/flock_error.tmp"; 56unlink($file); 57?> 58--EXPECTF-- 59*** Testing error conditions *** 60 61--- Iteration 0 --- 62Warning: flock(): Illegal operation argument in %s on line %d 63bool(false) 64 65--- Iteration 1 --- 66Warning: flock(): Illegal operation argument in %s on line %d 67bool(false) 68 69--- Iteration 2 --- 70Warning: flock(): Illegal operation argument in %s on line %d 71bool(false) 72 73--- Iteration 3 --- 74Warning: flock(): Illegal operation argument in %s on line %d 75bool(false) 76 77--- Iteration 4 --- 78Warning: flock() expects parameter 2 to be int, array given in %s on line %d 79NULL 80 81--- Iteration 5 --- 82Warning: flock() expects parameter 2 to be int, array given in %s on line %d 83NULL 84 85--- Iteration 6 --- 86Warning: flock() expects parameter 2 to be int, string given in %s on line %d 87NULL 88 89--- Iteration 7 --- 90Warning: flock() expects parameter 2 to be int, string given in %s on line %d 91NULL 92 93--- Iteration 8 --- 94Warning: flock() expects parameter 2 to be int, string given in %s on line %d 95NULL 96 97Warning: flock(): supplied resource is not a valid stream resource in %s on line %d 98bool(false) 99 100Warning: flock() expects parameter 1 to be resource, string given in %s on line %d 101NULL 102 103Warning: flock() expects at least 2 parameters, 0 given in %s on line %d 104NULL 105 106Warning: flock() expects at least 2 parameters, 1 given in %s on line %d 107NULL 108 109Warning: flock() expects at most 3 parameters, 4 given in %s on line %d 110NULL 111