note 68131 deleted from function.is-int by colder

From: Date: Fri, 23 Mar 2007 08:42:58 +0000
Subject: note 68131 deleted from function.is-int by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124738@lists.php.net to get a copy of this message
Note Submitter: stew{at}initiative.uk.com ---- 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))

« previous php.notes (#124738) next »