PHP code example of granam / scalar-enum

1. Go to this page and download the library: Download granam/scalar-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 / scalar-enum example snippets



$enum = \Granam\ScalarEnum\ScalarEnum::getEnum('foo bar');
echo $enum->getValue(); // foo bar
var_dump($enum->is('foo bar')); // true


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