1--TEST--
2Test fscanf() function: usage variations - objects
3--FILE--
4<?php
5
6/* Test fscanf() to scan a file to read objects */
7
8$file_path = __DIR__;
9
10echo "*** Test fscanf(): to read objects from a file ***\n";
11
12// declare a class
13class foo
14{
15  public $var1 = 1;
16  public $var2 = 2;
17  function __toString() {
18    return "Object";
19  }
20}
21
22// create an object
23$obj = new foo(); //creating new object
24
25// create a file
26$filename = "$file_path/fscanf_variation54.tmp";
27$file_handle = fopen($filename, "w");
28if($file_handle == false)
29  exit("Error:failed to open file $filename");
30//writing object to the file
31fwrite($file_handle, $obj);
32
33//closing the file
34fclose($file_handle);
35
36// various formats
37$formats = array( "%d", "%f", "%e", "%u", " %s", "%x", "%o");
38
39$counter = 1;
40
41// opening file for read
42$file_handle = fopen($filename, "r");
43  if($file_handle == false) {
44    exit("Error:failed to open file $filename");
45  }
46echo "\n-- iteration $counter --\n";
47
48foreach($formats as $format) {
49  var_dump( fscanf($file_handle,$format) );
50  rewind($file_handle);
51}
52
53fclose($file_handle);
54echo "\n*** Done ***";
55?>
56--CLEAN--
57<?php
58$file_path = __DIR__;
59$filename = "$file_path/fscanf_variation54.tmp";
60unlink($filename);
61?>
62--EXPECT--
63*** Test fscanf(): to read objects from a file ***
64
65-- iteration 1 --
66array(1) {
67  [0]=>
68  NULL
69}
70array(1) {
71  [0]=>
72  NULL
73}
74array(1) {
75  [0]=>
76  NULL
77}
78array(1) {
79  [0]=>
80  NULL
81}
82array(1) {
83  [0]=>
84  string(6) "Object"
85}
86array(1) {
87  [0]=>
88  NULL
89}
90array(1) {
91  [0]=>
92  NULL
93}
94
95*** Done ***
96