1--TEST-- 2BcMath\Number div(), mod(), divmod() by zero 3--EXTENSIONS-- 4bcmath 5--FILE-- 6<?php 7 8$values1 = ['100', '-100']; 9 10$values2 = [ 11 [0, 'int'], 12 [-0, 'int'], 13 ['0', 'string'], 14 ['-0', 'string'], 15 ['0.000', 'string'], 16 ['-0.000', 'string'], 17 [new BcMath\Number('0'), 'object'], 18 [new BcMath\Number('-0'), 'object'], 19 [new BcMath\Number('0.000'), 'object'], 20 [new BcMath\Number('-0.000'), 'object'], 21]; 22 23foreach ($values1 as $value1) { 24 $num = new BcMath\Number($value1); 25 26 foreach ($values2 as [$value2, $type]) { 27 echo "{$value1} and {$value2}: {$type}\n"; 28 echo "div: "; 29 try { 30 $num->div($value2); 31 echo "NG\n"; 32 } catch (Error $e) { 33 echo $e->getMessage() === 'Division by zero' ? 'OK' :'NG'; 34 echo "\n"; 35 } 36 37 echo "mod: "; 38 try { 39 $num->mod($value2); 40 echo "NG\n"; 41 } catch (Error $e) { 42 echo $e->getMessage() === 'Modulo by zero' ? 'OK' :'NG'; 43 echo "\n"; 44 } 45 46 echo "divmod: "; 47 try { 48 $num->divmod($value2); 49 echo "NG\n"; 50 } catch (Error $e) { 51 echo $e->getMessage() === 'Division by zero' ? 'OK' :'NG'; 52 echo "\n"; 53 } 54 echo "\n"; 55 } 56} 57?> 58--EXPECT-- 59100 and 0: int 60div: OK 61mod: OK 62divmod: OK 63 64100 and 0: int 65div: OK 66mod: OK 67divmod: OK 68 69100 and 0: string 70div: OK 71mod: OK 72divmod: OK 73 74100 and -0: string 75div: OK 76mod: OK 77divmod: OK 78 79100 and 0.000: string 80div: OK 81mod: OK 82divmod: OK 83 84100 and -0.000: string 85div: OK 86mod: OK 87divmod: OK 88 89100 and 0: object 90div: OK 91mod: OK 92divmod: OK 93 94100 and 0: object 95div: OK 96mod: OK 97divmod: OK 98 99100 and 0.000: object 100div: OK 101mod: OK 102divmod: OK 103 104100 and 0.000: object 105div: OK 106mod: OK 107divmod: OK 108 109-100 and 0: int 110div: OK 111mod: OK 112divmod: OK 113 114-100 and 0: int 115div: OK 116mod: OK 117divmod: OK 118 119-100 and 0: string 120div: OK 121mod: OK 122divmod: OK 123 124-100 and -0: string 125div: OK 126mod: OK 127divmod: OK 128 129-100 and 0.000: string 130div: OK 131mod: OK 132divmod: OK 133 134-100 and -0.000: string 135div: OK 136mod: OK 137divmod: OK 138 139-100 and 0: object 140div: OK 141mod: OK 142divmod: OK 143 144-100 and 0: object 145div: OK 146mod: OK 147divmod: OK 148 149-100 and 0.000: object 150div: OK 151mod: OK 152divmod: OK 153 154-100 and 0.000: object 155div: OK 156mod: OK 157divmod: OK 158