1--TEST--
2SPL: Test class_implements() function : variation
3--FILE--
4<?php
5echo "*** Testing class_implements() : variation ***\n";
6
7
8// Define error handler
9function test_error_handler($err_no, $err_msg, $filename, $linenum) {
10    if (error_reporting() & $err_no) {
11        // report non-silenced errors
12        echo "Error: $err_no - $err_msg, $filename($linenum)\n";
13    }
14}
15set_error_handler('test_error_handler');
16
17// Initialise function arguments not being substituted (if any)
18$autoload = true;
19
20//resource
21$res = fopen(__FILE__,'r');
22
23//get an unset variable
24$unset_var = 10;
25unset ($unset_var);
26
27// define some classes
28class classWithToString
29{
30    public function __toString() {
31        return "Class A object";
32    }
33}
34
35class classWithoutToString
36{
37}
38
39// heredoc string
40$heredoc = <<<EOT
41hello world
42EOT;
43
44// add arrays
45$index_array = array (1, 2, 3);
46$assoc_array = array ('one' => 1, 'two' => 2);
47
48//array of values to iterate over
49$inputs = array(
50
51      // int data
52      'int 0' => 0,
53      'int 1' => 1,
54      'int 12345' => 12345,
55      'int -12345' => -2345,
56
57      // float data
58      'float 10.5' => 10.5,
59      'float -10.5' => -10.5,
60      'float 12.3456789000e10' => 12.3456789000e10,
61      'float -12.3456789000e10' => -12.3456789000e10,
62      'float .5' => .5,
63
64      // array data
65      'empty array' => array(),
66      'int indexed array' => $index_array,
67      'associative array' => $assoc_array,
68      'nested arrays' => array('foo', $index_array, $assoc_array),
69
70      // null data
71      'uppercase NULL' => NULL,
72      'lowercase null' => null,
73
74      // boolean data
75      'lowercase true' => true,
76      'lowercase false' =>false,
77      'uppercase TRUE' =>TRUE,
78      'uppercase FALSE' =>FALSE,
79
80      // empty data
81      'empty string DQ' => "",
82      'empty string SQ' => '',
83
84      // object data
85      'instance of classWithToString' => new classWithToString(),
86      'instance of classWithoutToString' => new classWithoutToString(),
87
88      // undefined data
89      'undefined var' => @$undefined_var,
90
91      // unset data
92      'unset var' => @$unset_var,
93
94      //resource
95      'resource' => $res,
96);
97
98// loop through each element of the array for pattern
99
100foreach($inputs as $key =>$value) {
101      echo "\n--$key--\n";
102      try {
103        var_dump( class_implements($value, $autoload) );
104      } catch (\TypeError $e) {
105          echo $e->getMessage() . \PHP_EOL;
106      }
107};
108
109fclose($res);
110
111?>
112--EXPECTF--
113*** Testing class_implements() : variation ***
114
115--int 0--
116class_implements(): Argument #1 ($object_or_class) must be of type object|string, int given
117
118--int 1--
119class_implements(): Argument #1 ($object_or_class) must be of type object|string, int given
120
121--int 12345--
122class_implements(): Argument #1 ($object_or_class) must be of type object|string, int given
123
124--int -12345--
125class_implements(): Argument #1 ($object_or_class) must be of type object|string, int given
126
127--float 10.5--
128class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
129
130--float -10.5--
131class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
132
133--float 12.3456789000e10--
134class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
135
136--float -12.3456789000e10--
137class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
138
139--float .5--
140class_implements(): Argument #1 ($object_or_class) must be of type object|string, float given
141
142--empty array--
143class_implements(): Argument #1 ($object_or_class) must be of type object|string, array given
144
145--int indexed array--
146class_implements(): Argument #1 ($object_or_class) must be of type object|string, array given
147
148--associative array--
149class_implements(): Argument #1 ($object_or_class) must be of type object|string, array given
150
151--nested arrays--
152class_implements(): Argument #1 ($object_or_class) must be of type object|string, array given
153
154--uppercase NULL--
155class_implements(): Argument #1 ($object_or_class) must be of type object|string, null given
156
157--lowercase null--
158class_implements(): Argument #1 ($object_or_class) must be of type object|string, null given
159
160--lowercase true--
161class_implements(): Argument #1 ($object_or_class) must be of type object|string, bool given
162
163--lowercase false--
164class_implements(): Argument #1 ($object_or_class) must be of type object|string, bool given
165
166--uppercase TRUE--
167class_implements(): Argument #1 ($object_or_class) must be of type object|string, bool given
168
169--uppercase FALSE--
170class_implements(): Argument #1 ($object_or_class) must be of type object|string, bool given
171
172--empty string DQ--
173Error: 2 - class_implements(): Class  does not exist and could not be loaded, %s(%d)
174bool(false)
175
176--empty string SQ--
177Error: 2 - class_implements(): Class  does not exist and could not be loaded, %s(%d)
178bool(false)
179
180--instance of classWithToString--
181array(1) {
182  ["Stringable"]=>
183  string(10) "Stringable"
184}
185
186--instance of classWithoutToString--
187array(0) {
188}
189
190--undefined var--
191class_implements(): Argument #1 ($object_or_class) must be of type object|string, null given
192
193--unset var--
194class_implements(): Argument #1 ($object_or_class) must be of type object|string, null given
195
196--resource--
197class_implements(): Argument #1 ($object_or_class) must be of type object|string, resource given
198