Type representation interfaces
A set of interfaces to provide a generic API to get the
string,
integer,
float,
boolean
and array representation of an object.
Example
use NoreSources\IntegerRepresentation;
use NoreSources\StringRepresentation;
class Three implements IntegerRepresentation, StringRepresentation {
// IntegerRepresentation
public function getIntegerValue () {
return 3;
}
// StringRepresentation is just a syntactic sugar to indicates the object implements the __toString magic method
public function __toString () {
return 'three';
}
}
$t = new Three();
if ($t instanceof StringRepresentation)
echo (\strval ($t) . PHP_EOL); // "three"
if ($t instanceof IntegerRepresentation)
echo ($t->getIntegerValue () . PHP_EOL); // 3
// Or using TypeConversion
echo (TypeConversion::toString ($t) . PHP_EOL); // "three"