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--CLEAN--
40<?php
41unlink(__DIR__."/007_variation15.tmp");
42?>
43--EXPECTF--
44*** Test fopen() & fclose() functions:  with 'xt' mode ***
45resource(%d) of type (stream)
46string(6) "stream"
47int(0)
48int(37)
49int(37)
50
51Notice: fread(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
52bool(false)
53int(0)
54bool(true)
55string(7) "Unknown"
56
57Warning: fopen(%s): Failed to open stream: File exists in %s on line %d
58*** Done ***
59