1--TEST--
2Test readdir() function : usage variations - different file names
3--FILE--
4<?php
5/* Prototype  : string readdir([resource $dir_handle])
6 * Description: Read directory entry from dir_handle
7 * Source code: ext/standard/dir.c
8 */
9
10/*
11 * Pass a directory handle pointing to a directory that contains
12 * files with different file names to test how readdir() reads them
13 */
14
15echo "*** Testing readdir() : usage variations ***\n";
16
17$dir_path = dirname(__FILE__) . "/readdir_variation4/";
18mkdir($dir_path);
19
20// heredoc string
21$heredoc = <<<EOT
22hd_file
23EOT;
24
25$inputs = array(
26
27       // int data
28/*1*/  0,
29       1,
30       12345,
31       -2345,
32
33       // float data
34/*5*/  10.5,
35       -10.5,
36       12.3456789000e10,
37       12.3456789000E-10,
38       .5,
39
40       // empty data
41/*10*/ "",
42       array(),
43
44       // string data
45/*12*/ "double_file",
46       'single_file',
47       $heredoc,
48);
49
50$iterator = 1;
51foreach($inputs as $key => $input) {
52	echo "\n-- Iteration $iterator --\n";
53	$handle = "fp{$iterator}";
54	var_dump( $$handle = fopen(@"$dir_path$input.tmp", 'w') );
55	var_dump( fwrite($$handle, $key));
56	fclose($$handle);
57	$iterator++;
58};
59
60echo "\n-- Call to readdir() --\n";
61$dir_handle = opendir($dir_path);
62while(FALSE !== ($file = readdir($dir_handle))){
63
64	// different OS order files differently so will
65	// store file names into an array so can use sorted in expected output
66	$contents[] = $file;
67
68	// remove files while going through directory
69	@unlink($dir_path . $file);
70}
71
72// more important to check that all contents are present than order they are returned in
73sort($contents);
74var_dump($contents);
75
76closedir($dir_handle);
77?>
78===DONE===
79--CLEAN--
80<?php
81$dir_path = dirname(__FILE__) . "/readdir_variation4/";
82rmdir($dir_path);
83?>
84--EXPECTF--
85*** Testing readdir() : usage variations ***
86
87-- Iteration 1 --
88resource(%d) of type (stream)
89int(1)
90
91-- Iteration 2 --
92resource(%d) of type (stream)
93int(1)
94
95-- Iteration 3 --
96resource(%d) of type (stream)
97int(1)
98
99-- Iteration 4 --
100resource(%d) of type (stream)
101int(1)
102
103-- Iteration 5 --
104resource(%d) of type (stream)
105int(1)
106
107-- Iteration 6 --
108resource(%d) of type (stream)
109int(1)
110
111-- Iteration 7 --
112resource(%d) of type (stream)
113int(1)
114
115-- Iteration 8 --
116resource(%d) of type (stream)
117int(1)
118
119-- Iteration 9 --
120resource(%d) of type (stream)
121int(1)
122
123-- Iteration 10 --
124resource(%d) of type (stream)
125int(1)
126
127-- Iteration 11 --
128resource(%d) of type (stream)
129int(2)
130
131-- Iteration 12 --
132resource(%d) of type (stream)
133int(2)
134
135-- Iteration 13 --
136resource(%d) of type (stream)
137int(2)
138
139-- Iteration 14 --
140resource(%d) of type (stream)
141int(2)
142
143-- Call to readdir() --
144array(16) {
145  [0]=>
146  string(9) "-10.5.tmp"
147  [1]=>
148  string(9) "-2345.tmp"
149  [2]=>
150  string(1) "."
151  [3]=>
152  string(2) ".."
153  [4]=>
154  string(4) ".tmp"
155  [5]=>
156  string(7) "0.5.tmp"
157  [6]=>
158  string(5) "0.tmp"
159  [7]=>
160  string(17) "1.23456789E-9.tmp"
161  [8]=>
162  string(5) "1.tmp"
163  [9]=>
164  string(8) "10.5.tmp"
165  [10]=>
166  string(9) "12345.tmp"
167  [11]=>
168  string(16) "123456789000.tmp"
169  [12]=>
170  string(9) "Array.tmp"
171  [13]=>
172  string(15) "double_file.tmp"
173  [14]=>
174  string(11) "hd_file.tmp"
175  [15]=>
176  string(15) "single_file.tmp"
177}
178===DONE===
179