granam / strict-integer
This package is abandoned and no longer maintained.
The author suggests using the granam/integer package instead.
Base for lightweight integer containers with strict checks
Package info
github.com/jaroslavtyc/granam-strict-integer
Type:project
pkg:composer/granam/strict-integer
2.1.1
2015-09-16 08:40 UTC
Requires
- php: >=5.4
- granam/exception-hierarchy: ^2.1.2
- granam/integer: ~3.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.
<?php
use Granam\Strict\Integer\StrictInteger;
use Granam\Strict\Integer\Exceptions\WrongParameterType;
$integer = new StrictInteger(12345);
// int(12345)
var_dump($integer->getValue());
$integerFromString = new StrictInteger("124578", false /* explicitly non-strict */);
// int(124578)
var_dump($integerFromString->getValue());
$integerFromFloatString = new StrictInteger("987.0", false /* explicitly non-strict */);
// int(987)
var_dump($integerFromFloatString->getValue());
$integerFromTrue = new StrictInteger(true, false /* explicitly non-strict */);
// int(1)
var_dump($integerFromTrue->getValue());
$integerFromNull = new StrictInteger(null, false /* explicitly non-strict */);
// int(0)
var_dump($integerFromNull->getValue());
// ...
// The type check is strict by default, therefore only integer is allowed to be passed
try {
new StrictInteger(null);
} catch (WrongParameterType $integerException) {
// Something get wrong: On strict mode expected integer only, got NULL
die('Something get wrong: ' . $integerException->getMessage());
}