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