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