1--TEST--
2Test rewinddir() function : basic functionality
3--FILE--
4<?php
5/* Prototype  : void rewinddir([resource $dir_handle])
6 * Description: Rewind dir_handle back to the start
7 * Source code: ext/standard/dir.c
8 * Alias to functions: rewind
9 */
10
11/*
12 * Test basic functionality of rewinddir()
13 */
14
15echo "*** Testing rewinddir() : basic functionality ***\n";
16
17// include file.inc for create_files function
18include(dirname(__FILE__) . "/../file/file.inc");
19
20$dir_path1 = dirname(__FILE__) . "/rewinddir_basic_dir1";
21$dir_path2 = dirname(__FILE__) . "/rewinddir_basic_dir2";
22mkdir($dir_path1);
23mkdir($dir_path2);
24
25@create_files($dir_path1, 1);
26@create_files($dir_path2, 1, 'numeric', 0755, 1, 'w', 'file', 2);
27var_dump($dh1 = opendir($dir_path1));
28var_dump($dh2 = opendir($dir_path2));
29
30$data = array();
31echo "\n-- Read and rewind first directory (argument supplied) --\n";
32while(FALSE !== $file1 = readdir($dh1)) {
33	$data[] = $file1;
34}
35$first = $data[0];
36sort($data);
37var_dump($data);
38
39var_dump(rewinddir($dh1));
40var_dump(readdir($dh1) == $first);
41
42$data = array();
43echo "\n-- Read and rewind second directory (no argument supplied) --\n";
44while(FALSE !== $file2 = readdir()) {
45	$data[] = $file2;
46}
47$first = $data[0];
48sort($data);
49var_dump($data);
50
51var_dump(rewinddir());
52var_dump(readdir() == $first);
53
54closedir($dh1);
55closedir($dh2);
56
57delete_files($dir_path1, 1);
58delete_files($dir_path2, 1, 'file', 2);
59?>
60===DONE===
61--CLEAN--
62<?php
63$dir_path1 = dirname(__FILE__) . "/rewinddir_basic_dir1";
64$dir_path2 = dirname(__FILE__) . "/rewinddir_basic_dir2";
65rmdir($dir_path1);
66rmdir($dir_path2);
67?>
68--EXPECTF--
69*** Testing rewinddir() : basic functionality ***
70resource(%d) of type (stream)
71resource(%d) of type (stream)
72
73-- Read and rewind first directory (argument supplied) --
74array(3) {
75  [0]=>
76  string(1) "."
77  [1]=>
78  string(2) ".."
79  [2]=>
80  string(9) "file1.tmp"
81}
82NULL
83bool(true)
84
85-- Read and rewind second directory (no argument supplied) --
86array(3) {
87  [0]=>
88  string(1) "."
89  [1]=>
90  string(2) ".."
91  [2]=>
92  string(9) "file2.tmp"
93}
94NULL
95bool(true)
96===DONE===
97