yingchaophp/type-extension

PHP类型扩展

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Type:libraty

dev-master 2021-11-28 16:01 UTC

This package is auto-updated.

Last update: 2024-10-28 20:36:56 UTC


README

介绍

这是一个对PHP基础类型进行扩展的库,便于在参数传入和返回值中进行强制类型限制.

使用实例

// 文件在 sample/1.php

use TypeExtension\Single\File;


function fileis(File $file)
{
    return is_file($file);

}

$file = new File('sample/1.php');
// 应该是 true
var_dump(fileis($file));
try {
    $file = new File('sample/2.php');
} catch (\Exception $exception) {
    // 应该是 true
    var_dump($exception->getMessage() == 'not is file');

}