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 = dirname(__FILE__)."/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--EXPECT-- 52*** Testing fgets() with file opened in write only mode *** 53-- File opened in mode : w -- 54bool(true) 55int(0) 56bool(false) 57bool(false) 58int(0) 59bool(false) 60-- File opened in mode : wb -- 61bool(true) 62int(0) 63bool(false) 64bool(false) 65int(0) 66bool(false) 67-- File opened in mode : wt -- 68bool(true) 69int(0) 70bool(false) 71bool(false) 72int(0) 73bool(false) 74-- File opened in mode : a -- 75bool(true) 76int(0) 77bool(false) 78bool(false) 79int(0) 80bool(false) 81-- File opened in mode : ab -- 82bool(true) 83int(0) 84bool(false) 85bool(false) 86int(0) 87bool(false) 88-- File opened in mode : at -- 89bool(true) 90int(0) 91bool(false) 92bool(false) 93int(0) 94bool(false) 95-- File opened in mode : x -- 96bool(true) 97int(0) 98bool(false) 99bool(false) 100int(0) 101bool(false) 102-- File opened in mode : xb -- 103bool(true) 104int(0) 105bool(false) 106bool(false) 107int(0) 108bool(false) 109-- File opened in mode : xt -- 110bool(true) 111int(0) 112bool(false) 113bool(false) 114int(0) 115bool(false) 116Done 117