Diese Konstanten wurden definiert vom PHP-Core. Diese beziehen sich auch auf die PHP-, Zend-Engine- und SAPI-Module.
Diese Konstanten sind in PHP automatisch definiert.
Another way to determine PHP_INT_MIN:
<?php
define('PHP_INT_MIN', ~PHP_INT_MAX);
?>
It should work always:
MAX for 8bit-signed: 01111111
MIN for 8bit-signed: 10000000
In 32 bits:
php -r"echo (int)base_convert(str_repeat('1', 31), 2, 10) - PHP_INT_MAX;"
0
<?php echo ~(int)base_convert(str_repeat('1', 31), 2, 10); ?>
-2147483648
As PHP_INT_MAX is only available since PHP 4.4.0 and PHP 5.0.5 here is a function that should enable sensible values on most machines (16,32 & 64bit):-
<?php
function get_int_max()
{
$max=0x7fff;
$probe = 0x7fffffff;
while ($max == ($probe>>16))
{
$max = $probe;
$probe = ($probe << 16) + 0xffff;
}
return $max;
}
if (!defined('PHP_INT_MAX'))
{
define ('PHP_INT_MAX', get_int_max());
}
define ('PHP_INT_MIN', (int)(PHP_INT_MAX+1));
?>
You can get minimum integer size by adding 1 to PHP_INT_MAX. Just remember to use casting.
<?php
echo (int)(PHP_INT_MAX+1);
?>
Use get_defined_constants() to retrieve these constants.
<?php
print '<pre>';
print_r(get_defined_constants());
print '</pre>';
?>