1--TEST--
2Test fopen and fclose() functions - usage variations - "a+b" mode
3--FILE--
4<?php
5
6/* Test fopen() and fclose(): Opening the file in "a+b" mode,
7   checking for the file creation, write & read operations,
8   checking for the file pointer position,
9   and fclose function
10*/
11$file_path = __DIR__;
12require($file_path."/file.inc");
13
14create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 22, "bytes");
15$file = $file_path."/007_variation22.tmp";
16$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
17
18echo "*** Test fopen() & fclose() functions:  with 'a+b' mode ***\n";
19$file_handle = fopen($file, "a+b");  //opening the file "a+b" mode
20var_dump($file_handle);  //Check for the content of handle
21var_dump( get_resource_type($file_handle) );  //Check for the type of resource
22var_dump( fwrite($file_handle, $string) );  //Check for write operation; passes; expected:size of the $string
23rewind($file_handle);
24var_dump( fread($file_handle, 100) );  //Check for read operation; passes; expected: content of 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
29unlink($file);  //Deleting the file
30fclose( fopen($file, "a+b") );  //Opening the non-existing file in "a+b" mode, which will be created
31var_dump( file_exists($file) );  //Check for the existence of file
32echo "*** Done ***\n";
33--CLEAN--
34<?php
35unlink(__DIR__."/007_variation22.tmp");
36?>
37--EXPECTF--
38*** Test fopen() & fclose() functions:  with 'a+b' mode ***
39resource(%d) of type (stream)
40string(6) "stream"
41int(37)
42string(57) "line
43line of text
44liabcdefghij
45mnopqrst	uvwxyz
460123456789"
47int(57)
48bool(true)
49string(7) "Unknown"
50bool(true)
51*** Done ***
52