1--TEST-- 2Test abs() function : usage variations - different data types as $number arg 3--FILE-- 4<?php 5/* 6 * Pass different data types as $number argument to abs() to test behaviour 7 */ 8 9echo "*** Testing abs() : usage variations ***\n"; 10 11//get an unset variable 12$unset_var = 10; 13unset ($unset_var); 14 15// get a class 16class classA 17{ 18 public function __toString() { 19 return "abs"; 20 } 21} 22 23// heredoc string 24$heredoc = <<<EOT 25abs 26EOT; 27 28// get a resource variable 29$fp = fopen(__FILE__, "r"); 30 31// unexpected values to be passed to $number argument 32$inputs = array( 33 34 // null data 35/*10*/ NULL, 36 null, 37 38 // boolean data 39/*12*/ true, 40 false, 41 TRUE, 42 FALSE, 43 44 // empty data 45/*16*/ "", 46 '', 47 array(), 48 49 // string data 50/*19*/ "abs", 51 'abs', 52 $heredoc, 53 54 // object data 55/*22*/ new classA(), 56 57 // undefined data 58/*23*/ @$undefined_var, 59 60 // unset data 61/*24*/ @$unset_var, 62 63 // resource variable 64/*25*/ $fp 65); 66 67// loop through each element of $inputs to check the behavior of abs() 68$iterator = 1; 69foreach($inputs as $input) { 70 echo "\n-- Iteration $iterator --\n"; 71 try { 72 var_dump(abs($input)); 73 } catch (TypeError $e) { 74 echo $e->getMessage(), "\n"; 75 } 76 $iterator++; 77}; 78 79fclose($fp); 80?> 81--EXPECT-- 82*** Testing abs() : usage variations *** 83 84-- Iteration 1 -- 85int(0) 86 87-- Iteration 2 -- 88int(0) 89 90-- Iteration 3 -- 91int(1) 92 93-- Iteration 4 -- 94int(0) 95 96-- Iteration 5 -- 97int(1) 98 99-- Iteration 6 -- 100int(0) 101 102-- Iteration 7 -- 103abs(): Argument #1 ($num) must be of type int|float, string given 104 105-- Iteration 8 -- 106abs(): Argument #1 ($num) must be of type int|float, string given 107 108-- Iteration 9 -- 109abs(): Argument #1 ($num) must be of type int|float, array given 110 111-- Iteration 10 -- 112abs(): Argument #1 ($num) must be of type int|float, string given 113 114-- Iteration 11 -- 115abs(): Argument #1 ($num) must be of type int|float, string given 116 117-- Iteration 12 -- 118abs(): Argument #1 ($num) must be of type int|float, string given 119 120-- Iteration 13 -- 121abs(): Argument #1 ($num) must be of type int|float, classA given 122 123-- Iteration 14 -- 124int(0) 125 126-- Iteration 15 -- 127int(0) 128 129-- Iteration 16 -- 130abs(): Argument #1 ($num) must be of type int|float, resource given 131