note 103240 added to class.invalidargumentexception

From: Date: Sun, 03 Apr 2011 05:28:39 +0000
Subject: note 103240 added to class.invalidargumentexception
Groups: php.notes 
Request: Send a blank email to php-notes+get-178443@lists.php.net to get a copy of this message
I think that in this example: <?php function tripleInteger($int) { if(!is_int($int)) throw new InvalidArgumentException('tripleInteger function only accepts integers. Input was: '.$int); return $int * 3; } $x = tripleInteger(4); //$x == 12 $x = tripleInteger(2.5); //exception will be thrown as 2.5 is a float $x = tripleInteger('foo'); //exception will be thrown as 'foo' is a string $x = tripleInteger('4'); //exception will throw as '4' is also a string ?> function is_int() can be successfully changed to is_number() and this will be work fine. ---- Server IP: 69.147.83.197 Probable Submitter: 46.159.18.46 ---- Manual Page -- http://www.php.net/manual/en/class.invalidargumentexception.php Edit -- https://master.php.net/note/edit/103240 Del: integrated -- https://master.php.net/note/delete/103240/integrated Del: useless -- https://master.php.net/note/delete/103240/useless Del: bad code -- https://master.php.net/note/delete/103240/bad+code Del: spam -- https://master.php.net/note/delete/103240/spam Del: non-english -- https://master.php.net/note/delete/103240/non-english Del: in docs -- https://master.php.net/note/delete/103240/in+docs Del: other reasons-- https://master.php.net/note/delete/103240 Reject -- https://master.php.net/note/reject/103240 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178443) next »