This API defines object-oriented API to base types.
package lang.types {
public abstract class lang.types.Num
public final class lang.types.Int8 // "Byte", -128 to 127
public final class lang.types.Int16 // "Short", -32768 to 32767
public final class lang.types.Int32 // "Int", -2^31 to (2^31)- 1
public final class lang.types.Int64 // "Long", -2^63 to (2^63)- 1
public final class lang.types.Single // "Float", -3.4 x 10^38 to +3.4 x 10^38
public final class lang.types.Double // "Double", ±5.0 x 10^324 to ±1.7 x 10^308
public final class lang.types.Str // "String"
}
use lang\types\Str;
$greeting= new Str('Hello');
(string)$greeting; // "Hello"
$greeting->length(); // 5
$greeting->startsWith('Hell'); // TRUE
$greeting->endsWith('lo'); // FALSE
$greeting->contains('ello'); // TRUE
$greeting->indexOf('e'); // 1
$greeting->lastIndexOf('l'); // 3
$greeting->indexOf('a'); // -1
$greeting->concat('World'); // Str("Hello World") - in a new instance
Unicode support is realized via either the mbstring or iconv libraries, whichever is available.
use lang\types\Int8;
use lang\types\Int16;
use lang\types\Int32;
use lang\types\Int64;
$number= new Int32(6100);
(string)$number; // "6100"
$number->intValue(); // 6100
$number->doubleValue(); // 6100.0
new Int8(9999); // *** lang.IllegalArgumentException, out of range
64-bit support is realized via the bcmath extension on 32-bit platforms and versions of PHP.
use lang\types\Single;
use lang\types\Double;
$number= new Single(1.5);
(string)$number; // "1.5"
$number->intValue(); // 1
$number->doubleValue(); // 1.5
$number->round(0); // 2.0