PHP code example of georgii-web / php-typed-values

1. Go to this page and download the library: Download georgii-web/php-typed-values library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

georgii-web / php-typed-values example snippets


use PhpTypedValues\Integer\IntegerPositive;

$id = IntegerPositive::fromString('123');

$id = (int) '123';
if ($id <= 0) {
    throw new InvalidArgumentException('Invalid ID');
}

use PhpTypedValues\Integer\IntegerPositive;

readonly class Id extends IntegerPositive {}

Id::fromInt(123);

final readonly class Profile
{
    public function __construct(
        private IntegerPositive $id,
        private StringUsername $username,
        private FloatPositive|Undefined $rating,
    ) {}
}
bash
composer 
bash
composer 
bash
composer