1--TEST--
2Test fopen and fclose() functions - usage variations - "x+t" mode
3--FILE--
4<?php
5
6/* Test fopen() and fclose(): Opening the file in "x+t" mode,
7   checking for the file creation, write & read operations,
8   checking for the file pointer position,
9   checking for the warning msg when trying to open an existing file in "x+t" mode,
10   and fclose function
11*/
12$file_path = __DIR__;
13$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
14$file = $file_path."/007_variation16.tmp";
15
16echo "*** Test fopen() & fclose() functions:  with 'x+t' mode ***\n";
17$file_handle = fopen($file, "x+t");  //opening the non-existing file in "x+t" mode, file will be created
18var_dump($file_handle);  //Check for the content of handle
19var_dump( get_resource_type($file_handle) );  //Check for the type of resource
20var_dump( ftell($file_handle) );  //Initial file pointer position, expected at the beginning of the file
21var_dump( fwrite($file_handle, $string) );  //Check for write operation; passes; expected:size of the $string
22var_dump( ftell($file_handle) );  //File pointer position after write operation, expected at the end of the file
23rewind($file_handle);
24var_dump( fread($file_handle, 100) );  //Check for read operation; passes; expected: content of the file
25var_dump( ftell($file_handle) );  //File pointer position after read operation, expected at the end of the file
26var_dump( fclose($file_handle) );  //Check for close operation on the file handle
27var_dump( get_resource_type($file_handle) );  //Check whether resource is lost after close operation
28$file_handle = fopen($file, "x+t");  //Opening the existing data file in "x+t" mode to check for the warning message
29echo "*** Done ***\n";
30--CLEAN--
31<?php
32unlink(__DIR__."/007_variation16.tmp");
33?>
34--EXPECTF--
35*** Test fopen() & fclose() functions:  with 'x+t' mode ***
36resource(%d) of type (stream)
37string(6) "stream"
38int(0)
39int(37)
40int(37)
41string(37) "abcdefghij
42mnopqrst	uvwxyz
430123456789"
44int(37)
45bool(true)
46string(7) "Unknown"
47
48Warning: fopen(%s): Failed to open stream: File exists in %s on line %d
49*** Done ***
50