PHP code example of star / php-type

1. Go to this page and download the library: Download star/php-type 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/ */

    

star / php-type example snippets


use Star\Component\Type\ValueGuesser;

$int = ValueGuesser::fromMixed(12);
$int->isEmpty(); // false
$int->toBool(); // true
$int->toDate(); // throws Exception
$int->toFloat(); // 12.0
$int->toInteger(); // 12
$int->toString(); // "12"

use Star\Component\Type\BooleanValue;
use Star\Component\Type\ValueVisitor;

$true = BooleanValue::asTrue();
$true->acceptValueVisitor(
    new class implements ValueVisitor {
        ...
        public function visitFloatValue(float $value): void {
            // do your custom operation when the value is float.
        }
        ...
    }
);