fflush_variation4.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. Test fflush() function: usage variations - file opened in read-only mode
  3. --FILE--
  4. <?php
  5. /* Prototype: bool fflush ( resource $handle );
  6. Description: Flushes the output to a file
  7. */
  8. /* test fflush() with handle to a file opened in read-only mode as resource */
  9. $file_path = dirname(__FILE__);
  10. require $file_path.'/file.inc';
  11. echo "*** Testing fflush(): with file handles of files opened in various read modes ***\n";
  12. $file_modes = array("r", "rb", "rt");
  13. $file_name = "$file_path/fflush_variation4.tmp";
  14. $count = 1;
  15. foreach( $file_modes as $mode ) {
  16. echo "-- Iteration $count with file opened in $mode mode --\n";
  17. // creating a file
  18. $file_handle = fopen($file_name, "w");
  19. if($file_handle == false)
  20. exit("Error:failed to open file $file_name");
  21. fclose($file_handle);
  22. // opening the file in different read modes
  23. $file_handle = fopen($file_name, $mode);
  24. if($file_handle == false)
  25. exit("Error:failed to open file $file_name");
  26. var_dump( fflush($file_handle) );
  27. fclose($file_handle);
  28. unlink($file_name);
  29. $count++;
  30. }
  31. echo "\n*** Done ***";
  32. ?>
  33. --EXPECTF--
  34. *** Testing fflush(): with file handles of files opened in various read modes ***
  35. -- Iteration 1 with file opened in r mode --
  36. bool(true)
  37. -- Iteration 2 with file opened in rb mode --
  38. bool(true)
  39. -- Iteration 3 with file opened in rt mode --
  40. bool(true)
  41. *** Done ***