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 -- 112 113Notice: Array to string conversion in %sprint_variation1.php on line %d 114Array 115int(1) 116-- Iteration 10 -- 117 118Notice: Array to string conversion in %sprint_variation1.php on line %d 119Array 120int(1) 121-- Iteration 11 -- 122 123Notice: Array to string conversion in %sprint_variation1.php on line %d 124Array 125int(1) 126-- Iteration 12 -- 1271 128int(1) 129-- Iteration 13 -- 130 131int(1) 132-- Iteration 14 -- 1331 134int(1) 135-- Iteration 15 -- 136 137int(1) 138-- Iteration 16 -- 139 140int(1) 141-- Iteration 17 -- 142 143int(1) 144-- Iteration 18 -- 145sample object 146int(1) 147-- Iteration 19 -- 148Resource id #%d 149int(1) 150-- Iteration 20 -- 151 152int(1) 153-- Iteration 21 -- 154 155int(1) 156===DONE===