note 103240 deleted from class.invalidargumentexception by danbrown

From: Date: Mon, 04 Apr 2011 14:24:51 +0000
Subject: note 103240 deleted from class.invalidargumentexception by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178476@lists.php.net to get a copy of this message
Note Submitter: yorie at mail dot ru ---- 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.

« previous php.notes (#178476) next »