PHP code example of forrest79 / phpstan-narrow-types

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

    

forrest79 / phpstan-narrow-types example snippets


$arr = [3.14, 5, 10];
assert(is_type($arr, 'list<float|int>'));

assert(is_type($var, 'int'));
assert(is_type($var, 'int|string'));

/** @var array<string|int, list<Db\Row>> $arr
$arr = json_decode($data);

$arr = json_decode($data);
assert(is_type($arr, 'array<string|int, list<Db\Row>>'));