granam / strict-float
Base for lightweight float containers with strict checks
Installs: 234
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
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
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()); }