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