xp-lang/php-is-operator

PHP 的 is 运算符

v2.0.0 2024-03-24 13:02 UTC

This package is auto-updated.

Last update: 2024-08-24 14:08:18 UTC


README

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version

XP 编译器 添加 is 运算符的 PHP 语言插件。

之前

函数、语法和 XP 核心功能的混合 is()

is_string($value)                                  // for primitives, use is_[T]()
is_callable($value)                                // for pseudo types callable, array, object
is_array($value) || $value instanceof \Traversable // no is_iterable in PHP 5 and 7.0 
$value instanceof Date                             // for value types
null === $value || is_int($value)                  // nullable types cannot be tested directly
is('[:string]', $value)                            // for types beyond PHP type system
is('string|util.URI', $value)                      // for types beyond PHP type system

之后

任何可以作为参数、属性或返回类型的对象都可以与 is 运算符一起使用。

$value is string
$value is callable
$value is iterable
$value is Date
$value is ?int
$value is array<string, string>
$value is string|URI

安装

在项目中安装 XP 编译器后,还需要包括此插件。

$ composer require xp-framework/compiler
# ...

$ composer require xp-lang/php-is-operator
# ...

无需采取进一步行动。

另请参阅