fgets_variation2.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. Test fgets() function : usage variations - closed handle
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: string fgets ( resource $handle [, int $length] );
  7. Description: Gets a line from file pointer
  8. */
  9. /* try reading a line using fgets() using invalid handles
  10. - closed file handle
  11. - unset file handle
  12. */
  13. // include the header for common test function
  14. include ("file.inc");
  15. echo "*** Testing fgets() : usage variations ***\n";
  16. echo "-- Testing fgets() with closed handle --\n";
  17. // open the file for reading
  18. $file_handle = fopen(__FILE__, "r");
  19. // close the file
  20. fclose($file_handle);
  21. // read from closed file
  22. var_dump( fgets($file_handle) ); // default length
  23. var_dump( fgets($file_handle, 10) ); // with specific length
  24. echo "-- Testing fgets() with unset handle --\n";
  25. // open the file for reading
  26. $file_handle = fopen(__FILE__, "r");
  27. // unset the file handle
  28. unset($file_handle);
  29. //fgets using unset handle
  30. var_dump( fgets($file_handle) ); // default length
  31. var_dump( fgets($file_handle, 10) ); // with specific length
  32. echo "Done";
  33. ?>
  34. --EXPECTF--
  35. *** Testing fgets() : usage variations ***
  36. -- Testing fgets() with closed handle --
  37. Warning: fgets(): %d is not a valid stream resource in %s on line %d
  38. bool(false)
  39. Warning: fgets(): %d is not a valid stream resource in %s on line %d
  40. bool(false)
  41. -- Testing fgets() with unset handle --
  42. Notice: Undefined variable: file_handle in %s on line %d
  43. Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d
  44. bool(false)
  45. Notice: Undefined variable: file_handle in %s on line %d
  46. Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d
  47. bool(false)
  48. Done