PHPackages                             mawebdk/simple-datatypes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mawebdk/simple-datatypes

ActiveLibrary

mawebdk/simple-datatypes
========================

Simple datatypes with value restrictions.

4.0.0(8mo ago)06BSD-2-ClausePHPPHP ^8.3.6

Since Feb 24Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/mawebdk/simple-datatypes)[ Packagist](https://packagist.org/packages/mawebdk/simple-datatypes)[ RSS](/packages/mawebdk-simple-datatypes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (0)

simple-datatypes
================

[](#simple-datatypes)

Simple datatypes with value restrictions.

Use these classes instead of PHP's own internal datatypes to ensure values in parameters are within defined limitations.

Usage of MAInteger
------------------

[](#usage-of-mainteger)

Create a class extending MAInteger and implement method isValidValue() returning whether the given integer value is valid or not. Throw an MAIntegerException if unable to decide if the given integer value is valid or not.

Example of an integer class with integers in the range 1-65535 as the defined limitations.

```
class MyIntegerClass extends MAInteger
{
    public static function isValidValue(int $value): bool
    {
        return (($value >= 1) && ($value value;   // 123
echo $maInteger2->value;   // 456.
echo $maInteger3;          // null

```

MAInteger implements Stringable with the primary purpose to simplify logging and generate exception messages.

```
$myInteger = new MyIntegerClass(value: 123);

echo (string)$maInteger;   // MyIntegerClass{"value": 123}

```

Usage of MAString
-----------------

[](#usage-of-mastring)

Create a class extending MAString and implement method isValidValue() returning whether the given string value is valid or not. Throw an MAStringException if unable to decide if the given string value is valid or not.

Example of a string class for strings with a length between 1 and 100.

```
class MyStringClass extends MAString
{
    public static function isValidValue(string $value): bool
    {
        return (strlen($value) >= 1) && (strlen($value)
