fgetc_variation2.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. --TEST--
  2. Test fgetc() function : usage variations - closed handle
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: string fgetc ( resource $handle );
  7. Description: Gets character from file pointer
  8. */
  9. /* try reading a char using fgetc() 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 fgetc() : usage variations ***\n";
  16. echo "-- Testing fgetc() 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( fgetc($file_handle) );
  23. echo "-- Testing fgetc() with unset handle --\n";
  24. // open the file for reading
  25. $file_handle = fopen(__FILE__, "r");
  26. // unset the file handle
  27. unset($file_handle);
  28. //fgetc using unset handle
  29. var_dump( fgetc($file_handle) );
  30. echo "Done";
  31. ?>
  32. --EXPECTF--
  33. *** Testing fgetc() : usage variations ***
  34. -- Testing fgetc() with closed handle --
  35. Warning: fgetc(): %d is not a valid stream resource in %s on line %d
  36. bool(false)
  37. -- Testing fgetc() with unset handle --
  38. Notice: Undefined variable: file_handle in %s on line %d
  39. Warning: fgetc() expects parameter 1 to be resource, null given in %s on line %d
  40. bool(false)
  41. Done