1--TEST--
2Test file_put_contents() function : usage variation - different data types to write
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--FILE--
6<?php
7echo "*** Testing file_put_contents() : usage variation ***\n";
8
9// Define error handler
10function test_error_handler($err_no, $err_msg, $filename, $linenum) {
11    if (error_reporting() & $err_no) {
12        // report non-silenced errors
13        echo "Error: $err_no - $err_msg\n";
14    }
15}
16set_error_handler('test_error_handler');
17
18// Initialise function arguments not being substituted (if any)
19
20$filename = __DIR__ . '/fwriteVar5.tmp';
21
22
23
24//get an unset variable
25$unset_var = 10;
26unset ($unset_var);
27
28// define some classes
29class classWithToString
30{
31    public function __toString() {
32        return "Class A object";
33    }
34}
35
36class classWithoutToString
37{
38}
39
40// heredoc string
41$heredoc = <<<EOT
42hello world
43EOT;
44
45// add arrays
46$index_array = array (1, 2, 3);
47$assoc_array = array ('one' => 1, 'two' => 2);
48
49//array of values to iterate over
50$inputs = array(
51
52      // int data
53      'int 0' => 0,
54      'int 1' => 1,
55      'int 12345' => 12345,
56      'int -12345' => -2345,
57
58      // float data
59      'float 10.5' => 10.5,
60      'float -10.5' => -10.5,
61      'float 12.3456789000e10' => 12.3456789000e10,
62      'float -12.3456789000e10' => -12.3456789000e10,
63      'float .5' => .5,
64
65      // array data
66      'empty array' => array(),
67      'int indexed array' => $index_array,
68      'associative array' => $assoc_array,
69      'nested arrays' => array('foo', $index_array, $assoc_array),
70
71      // null data
72      'uppercase NULL' => NULL,
73      'lowercase null' => null,
74
75      // boolean data
76      'lowercase true' => true,
77      'lowercase false' =>false,
78      'uppercase TRUE' =>TRUE,
79      'uppercase FALSE' =>FALSE,
80
81      // empty data
82      'empty string DQ' => "",
83      'empty string SQ' => '',
84
85      // object data
86      'instance of classWithToString' => new classWithToString(),
87      'instance of classWithoutToString' => new classWithoutToString(),
88
89      // undefined data
90      'undefined var' => @$undefined_var,
91
92      // unset data
93      'unset var' => @$unset_var,
94);
95
96// loop through each element of the array for str
97
98foreach($inputs as $key =>$value) {
99      echo "\n--$key--\n";
100      file_put_contents($filename, $value);
101      readfile($filename);
102};
103unlink($filename);
104
105?>
106--EXPECT--
107*** Testing file_put_contents() : usage variation ***
108
109--int 0--
1100
111--int 1--
1121
113--int 12345--
11412345
115--int -12345--
116-2345
117--float 10.5--
11810.5
119--float -10.5--
120-10.5
121--float 12.3456789000e10--
122123456789000
123--float -12.3456789000e10--
124-123456789000
125--float .5--
1260.5
127--empty array--
128
129--int indexed array--
130123
131--associative array--
13212
133--nested arrays--
134Error: 2 - Array to string conversion
135Error: 2 - Array to string conversion
136fooArrayArray
137--uppercase NULL--
138
139--lowercase null--
140
141--lowercase true--
1421
143--lowercase false--
144
145--uppercase TRUE--
1461
147--uppercase FALSE--
148
149--empty string DQ--
150
151--empty string SQ--
152
153--instance of classWithToString--
154Class A object
155--instance of classWithoutToString--
156
157--undefined var--
158
159--unset var--
160