note 97006 added to function.is-int

From: Date: Sat, 27 Mar 2010 16:22:04 +0000
Subject: note 97006 added to function.is-int
Groups: php.notes 
Request: Send a blank email to php-notes+get-167453@lists.php.net to get a copy of this message
Keep in mind that is_int() operates in signed fashion, not unsigned, and is limited to the word size of the environment php is running in. In a 32-bit environment: <?php is_int( 2147483647 ); // true is_int( 2147483648 ); // false is_int( 9223372036854775807 ); // false is_int( 9223372036854775808 ); // false ?> In a 64-bit environment: <?php is_int( 2147483647 ); // true is_int( 2147483648 ); // true is_int( 9223372036854775807 ); // true is_int( 9223372036854775808 ); // false ?> If you find yourself deployed in a 32-bit environment where you are required to deal with numeric confirmation of integers (and integers only) potentially breaching the 32-bit span, you can combine is_int() with is_float() to guarantee a cover of the full, signed 64-bit span: <?php $small = 2147483647; // will always be true for is_int(), but never for is_float() $big = 9223372036854775807; // will only be true for is_int() in a 64-bit environment if( is_int($small) || is_float($small) ); // passes in a 32-bit environment if( is_int($big) || is_float($big) ); // passes in a 32-bit environment ?> ---- Server IP: 80.67.10.226 Probable Submitter: 83.227.160.33 ---- Manual Page -- http://www.php.net/manual/en/function.is-int.php Edit -- https://master.php.net/note/edit/97006 Del: integrated -- https://master.php.net/note/delete/97006/integrated Del: useless -- https://master.php.net/note/delete/97006/useless Del: bad code -- https://master.php.net/note/delete/97006/bad+code Del: spam -- https://master.php.net/note/delete/97006/spam Del: non-english -- https://master.php.net/note/delete/97006/non-english Del: in docs -- https://master.php.net/note/delete/97006/in+docs Del: other reasons-- https://master.php.net/note/delete/97006 Reject -- https://master.php.net/note/reject/97006 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167453) next »