--TEST--
Test intval() function
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
echo "*** Testing intval() with valid integer values ***\n";
$valid_ints = array(
'0',
'1',
'-1',
'-2147483648', '-2147483647',
2147483647, 2147483640,
0x123B, '0x12ab',
'0Xfff',
'0XFA',
-0x80000000, '0x7fffffff', 0x7FFFFFFF, '0123', 01912, -020000000000, 017777777777, );
echo "\n***Output with default base value ie 10 ***\n";
foreach ($valid_ints as $value ) {
var_dump( intval($value) );
}
echo "\n***Output with base value of 10( explicitly passed as argument) ***\n";
foreach ($valid_ints as $value ) {
var_dump( intval($value, 10) );
}
echo "\n***Output with base value of 16 ***\n";
foreach ($valid_ints as $value ) {
var_dump( intval($value, 16) );
}
echo "\n***Output with base value of 8 ***\n";
foreach ($valid_ints as $value ) {
var_dump( intval($value, 8) );
}
echo "\n*** Testing intval() on non integer types ***\n";
$fp = fopen (__FILE__, "r");
fclose($fp);
$dfp = opendir ( dirname(__FILE__) );
closedir($dfp);
$unset_var = 10;
unset ($unset_var);
$not_int_types = array (
'-2147483649', '2147483648', '-0x80000001', '0x800000001', '020000000001', '-020000000001', 0.0,
-0.1,
1.0,
1e5,
-1e6,
1E8,
-1E9,
10.0000000000000000005,
10.5e+5,
$fp,
$dfp,
array(),
array(0),
array(1),
array(NULL),
array(null),
array("string"),
array(true),
array(TRUE),
array(false),
array(FALSE),
array(1,2,3,4),
array(1 => "One", "two" => 2),
"",
'',
"0",
'0',
"1",
'1',
"\x01",
'\x01',
"\01",
'\01',
'string',
"string",
"true",
"FALSE",
'false',
'TRUE',
"NULL",
'null',
true,
false,
TRUE,
FALSE,
@$unset_var,
@$undefined_var
);
foreach ($not_int_types as $type ) {
var_dump( intval($type) );
}
echo "\n*** Testing error conditions ***\n";
var_dump( intval() );
var_dump( intval(TRUE, FALSE, TRUE) );
echo "\n--- Done ---\n";
?>
--EXPECTF--
*** Testing intval() with valid integer values ***
***Output with default base value ie 10 ***
int(0)
int(1)
int(-1)
int(-2147483648)
int(-2147483647)
int(2147483647)
int(2147483640)
int(4667)
int(0)
int(0)
int(0)
int(-2147483648)
int(0)
int(2147483647)
int(123)
int(1)
int(-2147483648)
int(2147483647)
***Output with base value of 10( explicitly passed as argument) ***
int(0)
int(1)
int(-1)
int(-2147483648)
int(-2147483647)
int(2147483647)
int(2147483640)
int(4667)
int(0)
int(0)
int(0)
int(-2147483648)
int(0)
int(2147483647)
int(123)
int(1)
int(-2147483648)
int(2147483647)
***Output with base value of 16 ***
int(0)
int(1)
int(-1)
int(-2147483648)
int(-2147483648)
int(2147483647)
int(2147483640)
int(4667)
int(4779)
int(4095)
int(250)
int(-2147483648)
int(2147483647)
int(2147483647)
int(291)
int(1)
int(-2147483648)
int(2147483647)
***Output with base value of 8 ***
int(0)
int(1)
int(-1)
int(-9020)
int(-9020)
int(2147483647)
int(2147483640)
int(4667)
int(0)
int(0)
int(0)
int(-2147483648)
int(0)
int(2147483647)
int(83)
int(1)
int(-2147483648)
int(2147483647)
*** Testing intval() on non integer types ***
int(-2147483648)
int(2147483647)
int(0)
int(0)
int(2147483647)
int(-2147483648)
int(0)
int(0)
int(1)
int(100000)
int(-1000000)
int(100000000)
int(-1000000000)
int(10)
int(1050000)
int(%d)
int(%d)
int(0)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(1)
int(0)
int(0)
int(0)
int(0)
int(1)
int(1)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(1)
int(0)
int(1)
int(0)
int(0)
int(0)
*** Testing error conditions ***
Warning: Wrong parameter count for intval() in %s on line %d
NULL
Warning: Wrong parameter count for intval() in %s on line %d
NULL
--- Done ---