Class to simulate enums in PHP I have been reading this thread on Stack Overflow about simulating enums in PHP and it seems that the most common approach is to use class constants. My problem with that is I can't use it for type hints, so I have added a static function that checks if a value is defined as one of the constants.

class DataType
{
    const BIT = 'BIT';
    const TINYINT = 'TINYINT';
    const SMALLINT = 'SMALLINT';
    const MEDIUMINT = 'MEDIUMINT';
    const INT = 'INT';
    const INTEGER = 'INTEGER';
    const BIGINT = 'BIGINT';
    const FLOAT = 'FLOAT';
    const DECIMAL = 'DECIMAL';
    const NUMERIC = 'NUMERIC';
    const DATE = 'DATE';
    const TIME = 'TIME';
    const TIMESTAMP = 'TIMESTAMP';
    const DATETIME = 'DATETIME';
    const YEAR = 'YEAR';
    const CHAR = 'CHAR';
    const VARCHAR = 'VARCHAR';

    static public function Defines($const)
    {
        $cls = new ReflectionClass(__CLASS__);
        foreach($cls-&gt;getConstants() as $key=&gt;$value)
        {
            if($value == $const)
            {
                return true;
            }
        }

        return false;
    }
}


Any thoughts on improving the code are welcome.
Why not just pass the data type you are looking for as a second argument to get_Type() then call the Defines() or similar method inside to verify it is the correct type? You can even provide a default data type should you use one more frequently.

function get_Type( $value, $DataType = VARCHAR ) {
    if( ! $this-&gt;Defines( $DataType ) ) { return FALSE; }

    //rest of method
}


Since you only want to test a given "DataType", I'd rewrite Defines() to use in_array() rather than loop through all the constants manually. Which BTW, you don't need to declare the $key=&gt; bit in a foreach loop unless you are actually going to use the key. 

function Defines( $const ) { return in_array( $const, $this-&gt;getConstants() ); }


I wrote this non-static, don't know if it needs to be static or not, but I tend to avoid static if at all possible.

I'd also like to point out that your method names conflict with PHP functions or aren't very descriptive. With the former you run the chance of your code conflicting with something else, or confusing people as to its purpose. With the latter you just confuse people. define() is a PHP function, so Defines() is close enough that it might cause issues or become confusing. get_Type() looks too much like you are fetching the data type rather than comparing it.

I hope this answer helps, if not then I'd add those last two comments to your actual question so more people might be able to help. That's what helped me to understand what you were trying to accomplish a lot better than the original explanation. If I actually understood it. Anyways, it seems much clearer now. Good Luck!