import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / 007_variation16.php
blobac719eb5cdc91b798cf4ea93d72f6353e6d16b18
1 <?php
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 "x+t" 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 "x+t" mode,
18 and fclose function
20 $file_path = dirname(__FILE__);
21 $string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
22 $file = $file_path."/007_variation16.tmp";
24 echo "*** Test fopen() & fclose() functions: with 'x+t' mode ***\n";
25 $file_handle = fopen($file, "x+t"); //opening the non-existing file in "x+t" 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 begining 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; passes; expected: content of the file
33 var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end 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, "x+t"); //Opening the existing data file in "x+t" mode to check for the warning message
37 echo "*** Done ***\n"; <?php
38 unlink(dirname(__FILE__)."/007_variation16.tmp");