note 98312 added to function.gettype
| From: | SoN9ne at gmail dot com | Date: | Tue, 08 Jun 2010 18:32:47 +0000 |
| Subject: | note 98312 added to function.gettype | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169948@lists.php.net to get a copy of this message | ||
The code below needs to be updated to work properly. I found that this way seems to work much
better.
<?php
/**
* Returns the type of the passed var
* - PHP warns against using gettype(), this is my workaround
*
* @param mixed $var
* @return string
*/
public function fetchType($var) {
if (is_bool($var)) $type='boolean';
else if (is_int($var)) $type='integer';
else if (is_float($var)) $type='float';
else if (is_string($var)) $type='string';
else if (is_array($var)) $type='array';
else if (is_object($var)) $type='object';
else if (is_resource($var)) $type='resource';
else if (is_null($var)) $type='NULL';
else $type='unknown type';
return $type;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 63.103.168.2
----
Manual Page -- http://www.php.net/manual/en/function.gettype.php
Edit -- https://master.php.net/note/edit/98312
Del: integrated -- https://master.php.net/note/delete/98312/integrated
Del: useless -- https://master.php.net/note/delete/98312/useless
Del: bad code -- https://master.php.net/note/delete/98312/bad+code
Del: spam -- https://master.php.net/note/delete/98312/spam
Del: non-english -- https://master.php.net/note/delete/98312/non-english
Del: in docs -- https://master.php.net/note/delete/98312/in+docs
Del: other reasons-- https://master.php.net/note/delete/98312
Reject -- https://master.php.net/note/reject/98312
Search -- https://master.php.net/manage/user-notes.php