1--TEST-- 2Test fgets() function : usage variations - write only modes (Bug #42036) 3--FILE-- 4<?php 5/* 6 Prototype: string fgets ( resource $handle [, int $length] ); 7 Description: Gets a line from file pointer 8*/ 9/* try fgets on files which are opened in non readable modes 10 w, wb, wt, 11 a, ab, at, 12 x, xb, xt 13*/ 14// include the header for common test function 15include ("file.inc"); 16 17echo "*** Testing fgets() with file opened in write only mode ***\n"; 18 19$file_modes = array("w", "wb", "wt", "a", "ab", "at", "x", "xb", "xt"); 20$filename = __DIR__."/fgets_variation1.tmp"; 21foreach ($file_modes as $file_mode ) { 22 echo "-- File opened in mode : $file_mode --\n"; 23 24 $file_handle = fopen($filename, $file_mode); 25 if(!$file_handle) { 26 echo "Error: failed to open file $filename!\n"; 27 exit(); 28 } 29 $data = "fgets_variation test"; 30 fwrite($file_handle, $data); 31 32 // rewind the file pointer to beginning of the file 33 var_dump( rewind($file_handle) ); 34 var_dump( ftell($file_handle) ); 35 var_dump( feof($file_handle) ); 36 37 // read from file 38 var_dump( fgets($file_handle) ); // expected : no chars should be read 39 var_dump( ftell($file_handle) ); // ensure that file pointer position is not changed 40 var_dump( feof($file_handle) ); // check if end of file pointer is set 41 42 // close the file 43 fclose($file_handle); 44 45 // delete the file 46 unlink($filename); 47} 48 49echo "Done\n"; 50?> 51--EXPECTF-- 52*** Testing fgets() with file opened in write only mode *** 53-- File opened in mode : w -- 54bool(true) 55int(0) 56bool(false) 57 58Notice: fgets(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 59bool(false) 60int(0) 61bool(false) 62-- File opened in mode : wb -- 63bool(true) 64int(0) 65bool(false) 66 67Notice: fgets(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 68bool(false) 69int(0) 70bool(false) 71-- File opened in mode : wt -- 72bool(true) 73int(0) 74bool(false) 75 76Notice: fgets(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 77bool(false) 78int(0) 79bool(false) 80-- File opened in mode : a -- 81bool(true) 82int(0) 83bool(false) 84 85Notice: fgets(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 86bool(false) 87int(0) 88bool(false) 89-- File opened in mode : ab -- 90bool(true) 91int(0) 92bool(false) 93 94Notice: fgets(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 95bool(false) 96int(0) 97bool(false) 98-- File opened in mode : at -- 99bool(true) 100int(0) 101bool(false) 102 103Notice: fgets(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 104bool(false) 105int(0) 106bool(false) 107-- File opened in mode : x -- 108bool(true) 109int(0) 110bool(false) 111 112Notice: fgets(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 113bool(false) 114int(0) 115bool(false) 116-- File opened in mode : xb -- 117bool(true) 118int(0) 119bool(false) 120 121Notice: fgets(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 122bool(false) 123int(0) 124bool(false) 125-- File opened in mode : xt -- 126bool(true) 127int(0) 128bool(false) 129 130Notice: fgets(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 131bool(false) 132int(0) 133bool(false) 134Done 135