note 52060 deleted from types.comparisons by philip

From: Date: Wed, 14 Dec 2005 02:37:38 +0000
Subject: note 52060 deleted from types.comparisons by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100102@lists.php.net to get a copy of this message
Note Submitter: Edgar dot Miller at gmail dot com ---- Hi out there, after not reading this part of the manual in past 5 years ;) , I found this great information about testing types for variables. I could not stop until i wrote a method to get all information from the 'Tabelle O-1'. so I put a number infront of every line of 'Tabelle O-1' and the method gives back the linenumber as result as it would be in 'Tabelle O-1'. define('TYPE_EMPTYSTRING',1); define('TYPE_UNDEFINED',2); define('TYPE_ARRAY',5); define('TYPE_BOOLEAN',6); define('TYPE_INTEGER',8); define('TYPE_INTEGER_ZERO',10); define('TYPE_STRING_INTEGER',12); define('TYPE_STRING_INTEGER_ZERO',13); define('TYPE_STRING',15); private function getTheType($var) { if ( gettype($var) == 'string' ) // 1 && 12 && 13 && 14 && 15 && 16 && 17 { if ( is_null($var) === false && isset($var) === true ) { if ( empty($var) === true && ((bool)($var)) === false ) // 1 && 13 { if ( $var == '' ) { $type = 1; } else { $type = 13; } } elseif ( is_numeric($var) === true) // 12 && 15 { $type = 12; // && 14 } else { $type = 15; // && 16 && 17 } } else { $type = 99 ; } } elseif ( gettype($var) == 'integer' ) { if ( empty($var) === false ) { $type = 8; // && 9 && 11 } else { $type = 10; } } elseif ( gettype($var) == 'boolean' ) { $type = 6; // && 7 } elseif ( gettype($var) == 'NULL' ) { $type = 2; // && 3 && 4 } elseif ( gettype($var) == 'array' ) { $type = 5; } else { $type = 99; } print "'".$var .' .. '. $type."'"; return $type; } now you can write small wrapper methods like this: function isNumberZero($var) { if ( getTheType($var) == TYPE_INTEGER_ZERO ) { return true; } else { return false; } } regards Erdal thanks to blueshoes and php for stating this information.

« previous php.notes (#100102) next »