PHP code example of granam / integer-enum

1. Go to this page and download the library: Download granam/integer-enum library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

granam / integer-enum example snippets



use \Granam\IntegerEnum\IntegerEnum;

$enum = IntegerEnum::getEnum(12345);
echo $enum->getValue(); // 12345
var_dump($enum->is('12345')); // false
var_dump($enum->is(12345)); // true
var_dump($enum->is($enum)); // true
var_dump($enum->is(IntegerEnum::getEnum(12345))); // true
var_dump($enum->is(IntegerEnum::getEnum(99999))); // false


try {
    \Granam\IntegerEnum\IntegerEnum::getEnum(null);
} catch(\Granam\IntegerEnum\Exceptions\UnexpectedValueToConvert $unexpectedValueToEnum) {
    echo $unexpectedValueToEnum->getMessage(); // Expected scalar or object with __toString method on strict mode, got NULL
}