convert ***sort builtins to use inout instead of references
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / dir / readdir_variation4.php
blobc61953d3c0305f3c8d6414e5bdaf0c4154cb115a
1 <?hh
2 /* Prototype : string readdir([resource $dir_handle])
3 * Description: Read directory entry from dir_handle
4 * Source code: ext/standard/dir.c
5 */
7 /*
8 * Pass a directory handle pointing to a directory that contains
9 * files with different file names to test how readdir() reads them
11 <<__EntryPoint>> function main(): void {
12 echo "*** Testing readdir() : usage variations ***\n";
14 $dir_path = dirname(__FILE__) . "/readdir_variation4/";
15 mkdir($dir_path);
17 // heredoc string
18 $heredoc = <<<EOT
19 hd_file
20 EOT;
22 $inputs = array(
24 // int data
25 /*1*/ 0,
27 12345,
28 -2345,
30 // float data
31 /*5*/ 10.5,
32 -10.5,
33 12.3456789000e10,
34 12.3456789000E-10,
35 .5,
37 // empty data
38 /*10*/ "",
39 array(),
41 // string data
42 /*12*/ "double_file",
43 'single_file',
44 $heredoc,
47 $iterator = 1;
48 foreach($inputs as $key => $input) {
49 echo "\n-- Iteration $iterator --\n";
50 $handle = "fp{$iterator}";
51 var_dump( $handle = fopen(@"$dir_path$input.tmp", 'w') );
52 try { var_dump( fwrite($handle, $key)); } catch (Exception $e) { var_dump($e->getMessage()); }
53 fclose($handle);
54 $iterator++;
57 echo "\n-- Call to readdir() --\n";
58 $dir_handle = opendir($dir_path);
59 $contents = array();
60 while(FALSE !== ($file = readdir($dir_handle))){
62 // different OS order files differently so will
63 // store file names into an array so can use sorted in expected output
64 $contents[] = $file;
66 // remove files while going through directory
67 @unlink($dir_path . $file);
70 // more important to check that all contents are present than order they are returned in
71 sort(inout $contents);
72 var_dump($contents);
74 closedir($dir_handle);
75 echo "===DONE===\n";
76 error_reporting(0);
77 $dir_path = dirname(__FILE__) . "/readdir_variation4/";
78 rmdir($dir_path);