note 103442 added to language.types.integer

From: Date: Wed, 13 Apr 2011 18:08:28 +0000
Subject: note 103442 added to language.types.integer
Groups: php.notes 
Request: Send a blank email to php-notes+get-178805@lists.php.net to get a copy of this message
If you need to convert a numeric string (or more to the point, an object that represents a numeric value) that is greater then PHP_INT_MAX, and you don't have GMP or BCMath installed, you can cast to float. For example, when using SimpleXMLElement, you sometimes have to cast the extracted values, such as xml attributes, because they are returned as SimpleXMLElements and not their values' native types. While print() has no trouble with converting them, other functions, such as max(), might not. But if you cast such a value with (int), and it is over PHP_INT_MAX, you will just get PHP_INT_MAX (and vice versa for negative numbers). The Q&D no-muss solution is to cast to (float) instead. ---- Server IP: 69.147.83.197 Probable Submitter: 174.46.204.210 ---- Manual Page -- http://www.php.net/manual/en/language.types.integer.php Edit -- https://master.php.net/note/edit/103442 Del: integrated -- https://master.php.net/note/delete/103442/integrated Del: useless -- https://master.php.net/note/delete/103442/useless Del: bad code -- https://master.php.net/note/delete/103442/bad+code Del: spam -- https://master.php.net/note/delete/103442/spam Del: non-english -- https://master.php.net/note/delete/103442/non-english Del: in docs -- https://master.php.net/note/delete/103442/in+docs Del: other reasons-- https://master.php.net/note/delete/103442 Reject -- https://master.php.net/note/reject/103442 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178805) next »