1--TEST--
2SPL: Test class_implements() function : variation
3--FILE--
4<?php
5/* Prototype  : array class_implements(mixed what [, bool autoload ])
6 * Description: Return all classes and interfaces implemented by SPL
7 * Source code: ext/spl/php_spl.c
8 * Alias to functions:
9 */
10
11echo "*** Testing class_implements() : variation ***\n";
12
13
14// Define error handler
15function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
16	if (error_reporting() != 0) {
17		// report non-silenced errors
18		echo "Error: $err_no - $err_msg, $filename($linenum)\n";
19	}
20}
21set_error_handler('test_error_handler');
22
23// Initialise function arguments not being substituted (if any)
24$class = 'Iterator';
25
26//resource
27$res = fopen(__FILE__,'r');
28
29//get an unset variable
30$unset_var = 10;
31unset ($unset_var);
32
33// define some classes
34class classWithToString
35{
36	public function __toString() {
37		return "Class A object";
38	}
39}
40
41class classWithoutToString
42{
43}
44
45// heredoc string
46$heredoc = <<<EOT
47hello world
48EOT;
49
50// add arrays
51$index_array = array (1, 2, 3);
52$assoc_array = array ('one' => 1, 'two' => 2);
53
54//array of values to iterate over
55$inputs = array(
56
57      // int data
58      'int 0' => 0,
59      'int 1' => 1,
60      'int 12345' => 12345,
61      'int -12345' => -2345,
62
63      // float data
64      'float 10.5' => 10.5,
65      'float -10.5' => -10.5,
66      'float 12.3456789000e10' => 12.3456789000e10,
67      'float -12.3456789000e10' => -12.3456789000e10,
68      'float .5' => .5,
69
70      // array data
71      'empty array' => array(),
72      'int indexed array' => $index_array,
73      'associative array' => $assoc_array,
74      'nested arrays' => array('foo', $index_array, $assoc_array),
75
76      // null data
77      'uppercase NULL' => NULL,
78      'lowercase null' => null,
79
80      // boolean data
81      'lowercase true' => true,
82      'lowercase false' =>false,
83      'uppercase TRUE' =>TRUE,
84      'uppercase FALSE' =>FALSE,
85
86      // empty data
87      'empty string DQ' => "",
88      'empty string SQ' => '',
89
90      // object data
91      'instance of classWithToString' => new classWithToString(),
92      'instance of classWithoutToString' => new classWithoutToString(),
93
94      // undefined data
95      'undefined var' => @$undefined_var,
96
97      // unset data
98      'unset var' => @$unset_var,
99
100      //resource
101      'resource' => $res,
102);
103
104// loop through each element of the array for pattern
105
106foreach($inputs as $key =>$value) {
107      echo "\n--$key--\n";
108      var_dump( class_implements($class, $value) );
109};
110
111fclose($res);
112
113?>
114===DONE===
115--EXPECTF--
116*** Testing class_implements() : variation ***
117
118--int 0--
119array(1) {
120  ["Traversable"]=>
121  string(11) "Traversable"
122}
123
124--int 1--
125array(1) {
126  ["Traversable"]=>
127  string(11) "Traversable"
128}
129
130--int 12345--
131array(1) {
132  ["Traversable"]=>
133  string(11) "Traversable"
134}
135
136--int -12345--
137array(1) {
138  ["Traversable"]=>
139  string(11) "Traversable"
140}
141
142--float 10.5--
143array(1) {
144  ["Traversable"]=>
145  string(11) "Traversable"
146}
147
148--float -10.5--
149array(1) {
150  ["Traversable"]=>
151  string(11) "Traversable"
152}
153
154--float 12.3456789000e10--
155array(1) {
156  ["Traversable"]=>
157  string(11) "Traversable"
158}
159
160--float -12.3456789000e10--
161array(1) {
162  ["Traversable"]=>
163  string(11) "Traversable"
164}
165
166--float .5--
167array(1) {
168  ["Traversable"]=>
169  string(11) "Traversable"
170}
171
172--empty array--
173Error: 2 - class_implements() expects parameter 2 to be boolean, array given, %s(%d)
174bool(false)
175
176--int indexed array--
177Error: 2 - class_implements() expects parameter 2 to be boolean, array given, %s(%d)
178bool(false)
179
180--associative array--
181Error: 2 - class_implements() expects parameter 2 to be boolean, array given, %s(%d)
182bool(false)
183
184--nested arrays--
185Error: 2 - class_implements() expects parameter 2 to be boolean, array given, %s(%d)
186bool(false)
187
188--uppercase NULL--
189array(1) {
190  ["Traversable"]=>
191  string(11) "Traversable"
192}
193
194--lowercase null--
195array(1) {
196  ["Traversable"]=>
197  string(11) "Traversable"
198}
199
200--lowercase true--
201array(1) {
202  ["Traversable"]=>
203  string(11) "Traversable"
204}
205
206--lowercase false--
207array(1) {
208  ["Traversable"]=>
209  string(11) "Traversable"
210}
211
212--uppercase TRUE--
213array(1) {
214  ["Traversable"]=>
215  string(11) "Traversable"
216}
217
218--uppercase FALSE--
219array(1) {
220  ["Traversable"]=>
221  string(11) "Traversable"
222}
223
224--empty string DQ--
225array(1) {
226  ["Traversable"]=>
227  string(11) "Traversable"
228}
229
230--empty string SQ--
231array(1) {
232  ["Traversable"]=>
233  string(11) "Traversable"
234}
235
236--instance of classWithToString--
237Error: 2 - class_implements() expects parameter 2 to be boolean, object given, %s(%d)
238bool(false)
239
240--instance of classWithoutToString--
241Error: 2 - class_implements() expects parameter 2 to be boolean, object given, %s(%d)
242bool(false)
243
244--undefined var--
245array(1) {
246  ["Traversable"]=>
247  string(11) "Traversable"
248}
249
250--unset var--
251array(1) {
252  ["Traversable"]=>
253  string(11) "Traversable"
254}
255
256--resource--
257Error: 2 - class_implements() expects parameter 2 to be boolean, resource given, %s(%d)
258bool(false)
259===DONE===
260