1. Go to this page and download the library: Download jeroenvanderlaan/php-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/ */
jeroenvanderlaan / php-types example snippets
use Jeroenvanderlaan\Types\Type;
use Jeroenvanderlaan\Types\TypeFormatter;
use Jeroenvanderlaan\Types\TypeInflector;
Type::get('float')->isCastableTo(Type::Int); // true
TypeInflector::typeof('John'); // Type::String
TypeFormatter::formatTypeOf([1, 2, 'a', 'b']); // 'list<int|string>'
use Jeroenvanderlaan\Types\Type;
use Jeroenvanderlaan\Types\TypeFormatter;
use Jeroenvanderlaan\Types\TypeInflector;
// Get a Type by name or alias
Type::get('int'); // Type::Int
Type::get('integer'); // Type::Int
// Parse union Types
Type::parse('int|float'); // [Type::Int, Type::Float]
// Inflect a Type from a value
TypeInflector::typeof('foobar'); // Type::String
TypeInflector::typeof([1, 2]); // Type::List
TypeInflector::typeof(['a' => 'b'])); // Type::Map
// Format a Type
TypeFormatter::formatType(Type::Int); // 'int'
TypeFormatter::formatType(Type::Int, Type::Float); // 'int|float'
// Format the Type of value
TypeFormatter::formatTypeOf(1); // 'int'
TypeFormatter::formatTypeOf([1, 'a']); // 'list<int|string>'
TypeFormatter::formatTypeOf([['a'], ['b']]); // 'list<list<string>>'
TypeFormatter::formatTypeOf(new stdClass); // 'stdClass'