note 52060 added to types.comparisons

From: Date: Wed, 20 Apr 2005 11:55:57 +0000
Subject: note 52060 added to types.comparisons
Groups: php.notes 
Request: Send a blank email to php-notes+get-88254@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/types.comparisons.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52060 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52060&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52060&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52060&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52060&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52060&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52060&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88254) next »