1--TEST-- 2Integer overflow 3--EXTENSIONS-- 4filter 5--FILE-- 6<?php 7$max = sprintf("%d", PHP_INT_MAX); 8switch($max) { 9case "2147483647": /* 32-bit systems */ 10 $min = "-2147483648"; 11 $overflow = "2147483648"; 12 $underflow = "-2147483649"; 13 break; 14case "9223372036854775807": /* 64-bit systems */ 15 $min = "-9223372036854775808"; 16 $overflow = "9223372036854775808"; 17 $underflow = "-9223372036854775809"; 18 break; 19default: 20 die("failed: unknown value for PHP_MAX_INT"); 21 break; 22} 23 24function test_validation($val, $msg) { 25 $f = filter_var($val, FILTER_VALIDATE_INT); 26 echo "$msg filtered: "; var_dump($f); // filtered value (or false) 27 echo "$msg is_long: "; var_dump(is_long($f)); // test validation 28 echo "$msg equal: "; var_dump($val == $f); // test equality of result 29} 30 31// PHP_INT_MAX 32test_validation($max, "max"); 33test_validation($overflow, "overflow"); 34test_validation($min, "min"); 35test_validation($underflow, "underflow"); 36?> 37--EXPECTF-- 38max filtered: int(%d) 39max is_long: bool(true) 40max equal: bool(true) 41overflow filtered: bool(false) 42overflow is_long: bool(false) 43overflow equal: bool(false) 44min filtered: int(-%d) 45min is_long: bool(true) 46min equal: bool(true) 47underflow filtered: bool(false) 48underflow is_long: bool(false) 49underflow equal: bool(false) 50