Create post-HADVAs expect files
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / file / 007_variation23.php
blobe77b043eb02634723cc04060a1efeed5b7c8f011
1 <?hh
2 /*
3 fopen() function:
4 Prototype: resource fopen(string $filename, string $mode
5 [, bool $use_include_path [, resource $context]] );
6 Description: Opens file or URL.
7 */
8 /*
9 fclose() function:
10 Prototype: bool fclose ( resource $handle );
11 Description: Closes an open file pointer
14 /* Test fopen() and fclose(): Opening the file in "xb" mode,
15 checking for the file creation, write & read operations,
16 checking for the file pointer position,
17 checking for the warning msg when trying to open an existing file in "xb" mode,
18 and fclose function */
19 <<__EntryPoint>> function main(): void {
21 $string = b"abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
22 $file = __SystemLib\hphp_test_tmppath('007_variation23.tmp');
24 echo "*** Test fopen() & fclose() functions: with 'xb' mode ***\n";
25 $file_handle = fopen($file, "xb"); //opening the non-existing file in "xb" mode, file will be created
26 var_dump($file_handle); //Check for the content of handle
27 var_dump( get_resource_type($file_handle) ); //Check for the type of resource
28 var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the beginning of the file
29 var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string
30 var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file
31 rewind($file_handle);
32 var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string
33 var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the beginning of the file
34 var_dump( fclose($file_handle) ); //Check for close operation on the file handle
35 var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation
36 $file_handle = fopen($file, "xb"); //Opening the existing data file in 'xb' mode to check for the warning message
37 echo "*** Done ***\n";
39 unlink($file);