1--TEST--
2Test print() function : usage variations
3--FILE--
4<?php
5
6echo "*** Testing print() function: with unexpected inputs for 'arg' argument ***\n";
7
8//get an unset variable
9$unset_var = 'string_val';
10unset($unset_var);
11
12//defining a class
13class sample  {
14  public function __toString() {
15    return "sample object";
16  }
17}
18
19//getting the resource
20$file_handle = fopen(__FILE__, "r");
21
22// array with different values for $input
23$inputs =  array (
24
25          // integer values
26/*1*/	  0,
27          1,
28          -2,
29          2147483647,
30          -2147483648,
31
32          // float values
33/*6*/	  10.5,
34          -20.5,
35          10.1234567e10,
36
37          // array values
38/*9*/	  array(),
39          array(0),
40          array(1, 2),
41
42          // boolean values
43/*12*/	  true,
44          false,
45          TRUE,
46          FALSE,
47
48          // null values
49/*16*/	  NULL,
50          null,
51
52          // objects
53/*18*/	  new sample(),
54
55          // resource
56/*19*/	  $file_handle,
57
58          // undefined variable
59/*20*/	  @$undefined_var,
60
61          // unset variable
62/*21*/	  @$unset_var
63);
64
65// loop through with each element of the $inputs array to test print() function
66$count = 1;
67foreach($inputs as $input) {
68  echo "-- Iteration $count --\n";
69  $res = print($input);
70  echo "\n";
71  var_dump($res);
72  $count ++;
73}
74
75fclose($file_handle);  //closing the file handle
76
77?>
78--EXPECTF--
79*** Testing print() function: with unexpected inputs for 'arg' argument ***
80-- Iteration 1 --
810
82int(1)
83-- Iteration 2 --
841
85int(1)
86-- Iteration 3 --
87-2
88int(1)
89-- Iteration 4 --
902147483647
91int(1)
92-- Iteration 5 --
93-2147483648
94int(1)
95-- Iteration 6 --
9610.5
97int(1)
98-- Iteration 7 --
99-20.5
100int(1)
101-- Iteration 8 --
102101234567000
103int(1)
104-- Iteration 9 --
105
106Warning: Array to string conversion in %s on line %d
107Array
108int(1)
109-- Iteration 10 --
110
111Warning: Array to string conversion in %s on line %d
112Array
113int(1)
114-- Iteration 11 --
115
116Warning: Array to string conversion in %s on line %d
117Array
118int(1)
119-- Iteration 12 --
1201
121int(1)
122-- Iteration 13 --
123
124int(1)
125-- Iteration 14 --
1261
127int(1)
128-- Iteration 15 --
129
130int(1)
131-- Iteration 16 --
132
133int(1)
134-- Iteration 17 --
135
136int(1)
137-- Iteration 18 --
138sample object
139int(1)
140-- Iteration 19 --
141Resource id #%d
142int(1)
143-- Iteration 20 --
144
145int(1)
146-- Iteration 21 --
147
148int(1)
149