PHP code example of granam / float-enum

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



use \Granam\FloatEnum\FloatEnum;

$enum = FloatEnum::getEnum(123);
echo $enum->getValue(); // 123
var_dump($enum->getValue()); // (float) 123.0
var_dump($enum->is(123.0)); // true
var_dump($enum->is(123)); // false
var_dump($enum->is('123.0')); // false
var_dump($enum->is($enum)); // true


try {
    \Granam\FloatEnum\FloatEnum::getEnum(null);
} catch(\Granam\FloatEnum\Exceptions\WrongValueForFloatEnum $wrongValueForFloatEnum) {
    echo $wrongValueForFloatEnum->getMessage(); // Expected float or object with __toString method on strict mode, got NULL
}