007_variation1.phpt 1.5 KB

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