note 68131 added to function.is-int

From: Date: Fri, 14 Jul 2006 13:00:33 +0000
Subject: note 68131 added to function.is-int
Groups: php.notes 
Request: Send a blank email to php-notes+get-114777@lists.php.net to get a copy of this message
is_int() and class objects If you wish to ask the question "Does this object contain an integer value?" for a class object, is_int() is not the function for you. is_int() does not work as may be expected with class objects, I'm guessing because it tries to evaluate the object itself rather than the value of the object. For example, assuming that $this->myid = 2, the following snippet will result in the output "false".... if(is_int((string)$this->myid)) print "true"; else print "false"; Neither will is_numeric work() as required; because it will return "true" for non-integers, such as 3.1, 6.7 and 0 (discussion about 0 as an integer referred to /dev/null for these purposes). Instead, use the following,which works exactly as required... if(is_numeric($this->myid) and intval($this->myid)) ---- Server IP: 83.138.144.80 Probable Submitter: 81.5.129.97 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.is-int.php Edit -- http://master.php.net/note/edit/68131 Del: integrated -- http://master.php.net/note/delete/68131/integrated Del: useless -- http://master.php.net/note/delete/68131/useless Del: bad code -- http://master.php.net/note/delete/68131/bad+code Del: spam -- http://master.php.net/note/delete/68131/spam Del: non-english -- http://master.php.net/note/delete/68131/non-english Del: in docs -- http://master.php.net/note/delete/68131/in+docs Del: other reasons-- http://master.php.net/note/delete/68131 Reject -- http://master.php.net/note/reject/68131 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114777) next »