PHP code example of improved / type

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

    

improved / type example snippets


use Improved as i;

$date = i\type_check(get_some_date(), DateTimeInterface::class);
$name = i\type_check($user->getName(), 'string');
$number = i\type_check(get_distance(), ['int', 'float']);

$foo = i\type_check(do_something(), Foo::class, new UnexpectedException('Wanted %2$s, not %1$s'));

type_describe('hello');        // string
type_describe(22);             // integer
type_describe(STDIN);          // stream resource
type_describe(new DateTime()); // instance of DateTime

type_describe('hello');         // string(5) "hello"
type_describe(22);              // int(22)
type_describe(["a", "b", "c"]); // array(3)