PHP code example of tebru / php-type

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

    

tebru / php-type example snippets


new TypeToken('string');

$typeShort = new TypeToken('int');
$typeLong = new TypeToken('integer');

$typeShort->getRawType(); // 'integer'
$typeLong->getRawType(); // 'integer'

$typeShort->getPhpType(); // 'integer'
$typeLong->getPhpType(); // 'integer'

$typeShort->isInteger(); // true
$typeLong->isInteger(); // true

$type = new TypeToken(\My\Foo::class);

$type->getRawType(); // 'My\Foo'
(string)$type; // 'My\Foo'
$type->getPhpType(); // 'object'
$type->isObject(); // true
$type->isA(\My\Foo::class); // true

$type = new TypeToken('My\Foo<string, My\Foo2>');

$type->getRawType(); // 'My\Foo'
(string)$type; // 'My\Foo<string, My\Foo2>'
$type->getPhpType(); // 'object'
$type->isObject(); // true
$type->isA(\My\Foo::class); // true

$generics = $type->getGenerics();
(string)$generics[0]; // 'string'
(string)$generics[1]; // 'My\Foo2'

new TypeToken('array<string, array<int>>');

TypeToken::createFromVariable($variable);