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