--- /dev/null
+--TEST--
+Test closedir() function : usage variations - close a file pointer
+--FILE--
+<?php
+/* Prototype : void closedir([resource $dir_handle])
+ * Description: Close directory connection identified by the dir_handle
+ * Source code: ext/standard/dir.c
+ * Alias to functions: close
+ */
+
+/*
+ * Create a file pointer using fopen() then try to close it using closedir()
+ */
+
+echo "*** Testing closedir() : usage variations ***\n";
+
+echo "\n-- Open a file using fopen() --\n";
+var_dump($fp = fopen(__FILE__, 'r'));
+
+echo "\n-- Try to close the file pointer using closedir() --\n";
+var_dump(closedir($fp));
+
+echo "\n-- Check file pointer: --\n";
+var_dump($fp);
+
+if(is_resource($fp)) {
+ fclose($fp);
+}
+?>
+===DONE===
+--EXPECTF--
+*** Testing closedir() : usage variations ***
+
+-- Open a file using fopen() --
+resource(%d) of type (stream)
+
+-- Try to close the file pointer using closedir() --
+Warning: closedir(): %d is not a valid Directory resource in %s on line %d
+
+-- Check file pointer: --
+resource(%d) of type (stream)
+===DONE===
--- /dev/null
+--TEST--
+Test readdir() function : usage variations - use file pointers
+--FILE--
+<?php
+/* Prototype : string readdir([resource $dir_handle])
+ * Description: Read directory entry from dir_handle
+ * Source code: ext/standard/dir.c
+ */
+
+/*
+ * Open a file pointer using fopen and pass to readdir() to test behaviour
+ */
+
+echo "*** Testing readdir() : usage variations ***\n";
+
+// get a resource variable
+var_dump($fp = fopen(__FILE__, "r"));
+var_dump( readdir($fp) );
+
+// get file length over 256 characters
+<<<EOT
+123456789012345678901234567890
+123456789012345678901234567890
+123456789012345678901234567890
+123456789012345678901234567890
+123456789012345678901234567890
+EOT;
+?>
+===DONE===
+--EXPECTF--
+*** Testing readdir() : usage variations ***
+resource(%d) of type (stream)
+
+Warning: readdir(): %d is not a valid Directory resource in %s on line %d
+bool(false)
+===DONE===
--- /dev/null
+--TEST--
+Test rewinddir() function : usage variations - file pointers
+--FILE--
+<?php
+/* Prototype : void rewinddir([resource $dir_handle])
+ * Description: Rewind dir_handle back to the start
+ * Source code: ext/standard/dir.c
+ * Alias to functions: rewind
+ */
+
+/*
+ * Pass a file pointer to rewinddir() to test behaviour
+ */
+
+echo "*** Testing rewinddir() : usage variations ***\n";
+
+echo "\n-- Open a file using fopen --\n";
+var_dump($fp = fopen(__FILE__, 'r'));
+
+$result1 = fread($fp, 5);
+var_dump(rewinddir($fp));
+$result2 = fread($fp, 5);
+
+echo "\n-- Check if rewinddir() has repositioned the file pointer --\n";
+if ($result1 === $result2) {
+ echo "rewinddir() works on file pointers\n";
+} else {
+ echo "rewinddir() does not work on file pointers\n";
+}
+?>
+===DONE===
+--EXPECTF--
+*** Testing rewinddir() : usage variations ***
+
+-- Open a file using fopen --
+resource(%d) of type (stream)
+NULL
+
+-- Check if rewinddir() has repositioned the file pointer --
+rewinddir() does not work on file pointers
+===DONE===