PHP code example of granam / boolean-enum

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



use \Granam\BooleanEnum\BooleanEnum;

$enum = BooleanEnum::getEnum(true);
echo $enum->getValue(); // 1
var_dump($enum->getValue()); // (bool) true
var_dump($enum->is(true)); // true
var_dump($enum->is(false)); // false
var_dump($enum->is(1)); // false
var_dump($enum->is($enum)); // true


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