import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fwrite_variation4.php
blob48c23f0bd1d66121cb47ae3c217612262c095fbd
1 <?php
2 /*
3 Prototype: int fwrite ( resource $handle,string string, [, int $length] );
4 Description: fwrite() writes the contents of string to the file stream pointed to by handle.
5 If the length arquement is given,writing will stop after length bytes have been
6 written or the end of string reached, whichever comes first.
7 fwrite() returns the number of bytes written or FALSE on error
8 */
11 echo "*** Testing fwrite() various operations ***\n";
13 // include the file.inc for Function: function delete_file($filename)
14 include ("file.inc");
17 Test fwrite with file opened in mode : x, xb, xt, x+, x+b, x+t
18 File having content of type numeric, text,text_with_new_line & alphanumeric
21 $file_modes = array("x","xb","xt","x+","x+b","x+t");
22 $file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
25 foreach($file_content_types as $file_content_type) {
26 echo "\n-- Testing fwrite() with file having content of type ". $file_content_type ." --\n";
28 /* open the file using $files_modes and perform fwrite() on it */
29 foreach($file_modes as $file_mode) {
30 echo "-- Opening file in $file_mode --\n";
32 $filename = dirname(__FILE__)."/fwrite_variation4.tmp"; // this is name of the file
34 $file_handle = fopen($filename, $file_mode);
35 if(!$file_handle) {
36 echo "Error: failed to fopen() file: $filename!";
37 exit();
40 $data_to_be_written="";
41 fill_buffer($data_to_be_written,$file_content_type,1024); //get the data of size 1024
43 /* Write the data into the file, verify it by checking the file pointer position, eof position,
44 filesize & by displaying the content */
45 // write data to the file
46 var_dump( ftell($file_handle) );
47 var_dump( fwrite($file_handle,$data_to_be_written,400));
48 var_dump( ftell($file_handle) );
49 var_dump( feof($file_handle) ); // expected: true
51 //check the filesize and content
52 // close the file, get the size and content of the file.
53 var_dump( fclose($file_handle) );
54 clearstatcache();//clears file status cache
55 var_dump( filesize($filename) );
56 var_dump(md5(file_get_contents($filename)));
57 // delete the file created
58 delete_file($filename); // delete file with name fwrite_variation4.tmp
59 } // end of inner foreach loop
60 } // end of outer foreach loop
62 echo "Done\n";