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};
103
104?>
105--CLEAN--
106<?php
107$filename = __DIR__ . '/fwriteVar5.tmp';
108unlink($filename);
109?>
110--EXPECT--
111*** Testing file_put_contents() : usage variation ***
112
113--int 0--
1140
115--int 1--
1161
117--int 12345--
11812345
119--int -12345--
120-2345
121--float 10.5--
12210.5
123--float -10.5--
124-10.5
125--float 12.3456789000e10--
126123456789000
127--float -12.3456789000e10--
128-123456789000
129--float .5--
1300.5
131--empty array--
132
133--int indexed array--
134123
135--associative array--
13612
137--nested arrays--
138Error: 2 - Array to string conversion
139Error: 2 - Array to string conversion
140fooArrayArray
141--uppercase NULL--
142
143--lowercase null--
144
145--lowercase true--
1461
147--lowercase false--
148
149--uppercase TRUE--
1501
151--uppercase FALSE--
152
153--empty string DQ--
154
155--empty string SQ--
156
157--instance of classWithToString--
158Class A object
159--instance of classWithoutToString--
160
161--undefined var--
162
163--unset var--
164