1--TEST-- 2Test fopen and fclose() functions - usage variations - "ab" mode 3--FILE-- 4<?php 5 6/* Test fopen() and fclose(): Opening the file in "ab" mode, 7 checking for the file creation, write & read operations, 8 checking for the file pointer position, 9 and fclose function 10*/ 11$file_path = __DIR__; 12require($file_path."/file.inc"); 13 14create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 21, "bytes"); 15$file = $file_path."/007_variation21.tmp"; 16$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; 17 18echo "*** Test fopen() & fclose() functions: with 'ab' mode ***\n"; 19$file_handle = fopen($file, "ab"); //opening the file "ab" mode 20var_dump($file_handle); //Check for the content of handle 21var_dump( get_resource_type($file_handle) ); //Check for the type of resource 22var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string 23rewind($file_handle); 24var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: false 25var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file 26var_dump( fclose($file_handle) ); //Check for close operation on the file handle 27var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation 28var_dump( filesize($file) ); //Check that data hasn't over written; Expected: Size of (initial data + newly added data) 29 30unlink($file); //Deleting the file 31fclose( fopen($file, "ab") ); //Opening the non-existing file in "ab" mode, which will be created 32var_dump( file_exists($file) ); //Check for the existence of file 33echo "*** Done ***\n"; 34?> 35--CLEAN-- 36<?php 37unlink(__DIR__."/007_variation21.tmp"); 38?> 39--EXPECTF-- 40*** Test fopen() & fclose() functions: with 'ab' mode *** 41resource(%d) of type (stream) 42string(6) "stream" 43int(37) 44 45Notice: fread(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d 46bool(false) 47int(0) 48bool(true) 49string(7) "Unknown" 50int(57) 51bool(true) 52*** Done *** 53