1--TEST-- 2Test fopen and fclose() functions - usage variations - "rb" mode 3--FILE-- 4<?php 5/* 6 fopen() function: 7 Prototype: resource fopen(string $filename, string $mode 8 [, bool $use_include_path [, resource $context]] ); 9 Description: Opens file or URL. 10*/ 11/* 12 fclose() function: 13 Prototype: bool fclose ( resource $handle ); 14 Description: Closes an open file pointer 15*/ 16 17/* Test fopen() and fclose(): Opening the file in "rb" mode, 18 checking for the file creation, write & read operations, 19 checking for the file pointer position, 20 and fclose function 21*/ 22$file_path = __DIR__; 23require($file_path."/file.inc"); 24 25create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 17, "bytes"); 26$file = $file_path."/007_variation17.tmp"; 27$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; 28 29echo "*** Test fopen() & fclose() functions: with 'rb' mode ***\n"; 30$file_handle = fopen($file, "rb"); //opening the file in "rb" mode 31var_dump($file_handle); //Check for the content of handle 32var_dump( get_resource_type($file_handle) ); //Check for the type of resource 33var_dump( ftell($file_handle) ); //Initial position of file pointer 34var_dump( fread($file_handle, 100) ); //Check for read operation 35var_dump( fwrite($file_handle, $string) ); //Check for write operation; fails 36var_dump( fclose($file_handle) ); //Check for close operation on the file handle 37var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation 38echo "*** Done ***\n"; 39--CLEAN-- 40<?php 41unlink(__DIR__."/007_variation17.tmp"); 42?> 43--EXPECTF-- 44*** Test fopen() & fclose() functions: with 'rb' mode *** 45resource(%d) of type (stream) 46string(6) "stream" 47int(0) 48string(20) "line 49line of text 50li" 51 52Notice: fwrite(): write of 37 bytes failed with errno=9 Bad file descriptor in %s on line %d 53bool(false) 54bool(true) 55string(7) "Unknown" 56*** Done *** 57