1--TEST-- 2Test nl2br() function : usage variations - unexpected values for 'str' argument 3--FILE-- 4<?php 5/* Prototype : string nl2br(string $str) 6 * Description: Inserts HTML line breaks before all newlines in a string. 7 * Source code: ext/standard/string.c 8*/ 9 10/* 11* Test nl2br() function by passing different types of values other than 12* expected type for 'str' argument 13*/ 14 15echo "*** Testing nl2br() : usage variations ***\n"; 16 17//get an unset variable 18$unset_var = 10; 19unset ($unset_var); 20 21//getting resource 22$file_handle = fopen(__FILE__, "r"); 23 24//defining class 25class Sample { 26 public function __toString() { 27 return "My String"; 28 } 29} 30 31//array of values to iterate over 32$values = array( 33 34 // int data 35 0, 36 1, 37 12345, 38 -2345, 39 40 // float data 41 10.5, 42 -10.5, 43 10.5e10, 44 10.6E-10, 45 .5, 46 47 // array data 48 array(), 49 array(0), 50 array(1), 51 array(1, 2), 52 array('color' => 'red', 'item' => 'pen'), 53 54 // null data 55 NULL, 56 null, 57 58 // boolean data 59 true, 60 false, 61 TRUE, 62 FALSE, 63 64 //resource 65 $file_handle, 66 67 // object data 68 new Sample(), 69 70 // undefined data 71 @$undefined_var, 72 73 // unset data 74 @$unset_var, 75); 76 77// loop through $values array to test nl2br() function with each element 78$count = 1; 79foreach($values as $value) { 80 echo "-- Iteration $count --\n"; 81 var_dump( nl2br($value) ); 82 $count ++ ; 83}; 84 85//closing the file handle 86fclose( $file_handle ); 87 88echo "Done"; 89?> 90--EXPECTF-- 91*** Testing nl2br() : usage variations *** 92-- Iteration 1 -- 93string(1) "0" 94-- Iteration 2 -- 95string(1) "1" 96-- Iteration 3 -- 97string(5) "12345" 98-- Iteration 4 -- 99string(5) "-2345" 100-- Iteration 5 -- 101string(4) "10.5" 102-- Iteration 6 -- 103string(5) "-10.5" 104-- Iteration 7 -- 105string(12) "105000000000" 106-- Iteration 8 -- 107string(7) "1.06E-9" 108-- Iteration 9 -- 109string(3) "0.5" 110-- Iteration 10 -- 111 112Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d 113NULL 114-- Iteration 11 -- 115 116Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d 117NULL 118-- Iteration 12 -- 119 120Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d 121NULL 122-- Iteration 13 -- 123 124Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d 125NULL 126-- Iteration 14 -- 127 128Warning: nl2br() expects parameter 1 to be string, array given in %s on line %d 129NULL 130-- Iteration 15 -- 131string(0) "" 132-- Iteration 16 -- 133string(0) "" 134-- Iteration 17 -- 135string(1) "1" 136-- Iteration 18 -- 137string(0) "" 138-- Iteration 19 -- 139string(1) "1" 140-- Iteration 20 -- 141string(0) "" 142-- Iteration 21 -- 143 144Warning: nl2br() expects parameter 1 to be string, resource given in %s on line %d 145NULL 146-- Iteration 22 -- 147string(9) "My String" 148-- Iteration 23 -- 149string(0) "" 150-- Iteration 24 -- 151string(0) "" 152Done 153