1--TEST-- 2Test range() function (errors) 3--INI-- 4precision=14 5--FILE-- 6<?php 7 8echo "\n*** Testing error conditions ***\n"; 9 10echo "\n-- Testing ( (low < high) && (step = 0) ) --\n"; 11try { 12 var_dump( range(1, 2, 0) ); 13} catch (\ValueError $e) { 14 echo $e->getMessage(), "\n"; 15} 16 17try { 18 var_dump( range("a", "b", 0) ); 19} catch (\ValueError $e) { 20 echo $e->getMessage(), "\n"; 21} 22 23echo "\n\n-- Testing ( (low > high) && (step = 0) ) --\n"; 24try { 25 var_dump( range(2, 1, 0) ); 26} catch (\ValueError $e) { 27 echo $e->getMessage(), "\n"; 28} 29 30try { 31 var_dump( range("b", "a", 0) ); 32} catch (\ValueError $e) { 33 echo $e->getMessage(), "\n"; 34} 35 36echo "\n\n-- Testing ( (low < high) && (high-low < step) ) --\n"; 37try { 38 var_dump( range(1.0, 7.0, 6.5) ); 39} catch (\ValueError $e) { 40 echo $e->getMessage(), "\n"; 41} 42 43echo "\n\n-- Testing ( (low > high) && (low-high < step) ) --\n"; 44try { 45 var_dump( range(7.0, 1.0, 6.5) ); 46} catch (\ValueError $e) { 47 echo $e->getMessage(), "\n"; 48} 49 50echo "\n\n-- Testing ( (low < high) && (high-low < step) ) for characters --\n"; 51try { 52 var_dump(range('a', 'z', 100)); 53} catch (\ValueError $e) { 54 echo $e->getMessage(), "\n"; 55} 56 57echo "\n\n-- Testing ( (low > high) && (low-high < step) ) for characters --\n"; 58try { 59 var_dump(range('z', 'a', 100)); 60} catch (\ValueError $e) { 61 echo $e->getMessage(), "\n"; 62} 63 64echo "\n-- Testing other conditions --\n"; 65try { 66 var_dump( range(-1, -2, 2) ); 67} catch (\ValueError $e) { 68 echo $e->getMessage(), "\n"; 69} 70 71try { 72 var_dump( range("a", "j", "z") ); 73} catch (\TypeError $e) { 74 echo $e->getMessage(), "\n"; 75} 76 77try { 78 var_dump( range(0, 1, "140962482048819216326.24") ); 79} catch (\ValueError $e) { 80 echo $e->getMessage(), "\n"; 81} 82 83echo "\n-- Testing Invalid steps --\n"; 84$step_arr = array( "string", NULL, FALSE, "", "\0" ); 85 86foreach( $step_arr as $step ) { 87 try { 88 var_dump( range( 1, 5, $step ) ); 89 } catch (\TypeError | \ValueError $e) { 90 echo $e->getMessage(), "\n"; 91 } 92} 93?> 94--EXPECTF-- 95*** Testing error conditions *** 96 97-- Testing ( (low < high) && (step = 0) ) -- 98range(): Argument #3 ($step) must not exceed the specified range 99range(): Argument #3 ($step) must not exceed the specified range 100 101 102-- Testing ( (low > high) && (step = 0) ) -- 103range(): Argument #3 ($step) must not exceed the specified range 104range(): Argument #3 ($step) must not exceed the specified range 105 106 107-- Testing ( (low < high) && (high-low < step) ) -- 108range(): Argument #3 ($step) must not exceed the specified range 109 110 111-- Testing ( (low > high) && (low-high < step) ) -- 112range(): Argument #3 ($step) must not exceed the specified range 113 114 115-- Testing ( (low < high) && (high-low < step) ) for characters -- 116range(): Argument #3 ($step) must not exceed the specified range 117 118 119-- Testing ( (low > high) && (low-high < step) ) for characters -- 120range(): Argument #3 ($step) must not exceed the specified range 121 122-- Testing other conditions -- 123range(): Argument #3 ($step) must not exceed the specified range 124range(): Argument #3 ($step) must be of type int|float, string given 125range(): Argument #3 ($step) must not exceed the specified range 126 127-- Testing Invalid steps -- 128range(): Argument #3 ($step) must be of type int|float, string given 129 130Deprecated: range(): Passing null to parameter #3 ($step) of type int|float is deprecated in %s on line %d 131range(): Argument #3 ($step) must not exceed the specified range 132range(): Argument #3 ($step) must not exceed the specified range 133range(): Argument #3 ($step) must be of type int|float, string given 134range(): Argument #3 ($step) must be of type int|float, string given 135