xp-lang / php-is-operator
PHP 的 is 运算符
v2.0.0
2024-03-24 13:02 UTC
Requires
- php: >=7.4.0
- xp-framework/compiler: ^9.0 | ^8.0
- xp-framework/core: ^12.0 | ^11.0 | ^10.0
Requires (Dev)
- xp-framework/test: ^2.0 | ^1.0
README
为 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 # ...
无需采取进一步行动。