PHP code example of skyzyx / strong-types

1. Go to this page and download the library: Download skyzyx/strong-types 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/ */

    

skyzyx / strong-types example snippets


use Skyzyx\StrongTypes\StringType;

$abc = new StringType('abc');

$v123 = new StringType(123);
#=> UnexpectedValueException:
#=> The Skyzyx\StrongTypes\StringType class expects a value of type string. 
#=> Received a value of type integer instead.

$abc->getValue();
#=> 'abc'

use Skyzyx\StrongTypes\StringType;

class FiveChars extends StringType
{
    public function __construct($s)
    {
        $this->setExactLength(5);
        parent::__construct($s);
    }
}

$abcde = new FiveChars('abcde');

$abc = new FiveChars('abc');
#=> Exception

$v12345 = new FiveChars(12345);
#=> Exception