granam / strict-float
This package is abandoned and no longer maintained.
The author suggests using the granam/float package instead.
Base for lightweight float containers with strict checks
Package info
github.com/jaroslavtyc/granam-strict-float
Type:project
pkg:composer/granam/strict-float
2.1.1
2015-09-10 11:51 UTC
Requires
- php: >=5.4
- granam/exception-hierarchy: ~2.1
- granam/float: ~1.0
- granam/strict-scalar: ~2.0
Requires (Dev)
- mockery/mockery: >=0.9
- phpunit/phpunit: ~4.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
PHP does not provide scalar type hinting yet (planned for PHP 7.0).
For that reason, if we want to be sure about scalar type, a type-checking class is the only chance.
Note: requires PHP 5.4+
<?php
use Granam\Strict\Float\StrictFloat;
use Granam\Strict\Float\Exceptions\WrongParameterType;
$float = new StrictFloat(123.456);
// double(123.456)
var_dump($float->getValue());
// string(7) "123.456"
var_dump((string)$float);
$float = new StrictFloat(null, false /* explicitly non-strict*/);
// double(0)
var_dump($float->getValue());
// string(0)
var_dump((string)$float);
try {
new StrictFloat(null);
} catch (WrongParameterType $floatException) {
// Something get wrong: On strict mode expected float only, got NULL
die('Something get wrong: ' . $floatException->getMessage());
}