Skip to content

Latest commit

 

History

History
executable file
·
61 lines (50 loc) · 2.48 KB

README.md

File metadata and controls

executable file
·
61 lines (50 loc) · 2.48 KB

Is operator for PHP

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

Plugin for the XP Compiler which adds an is operator to the PHP language.

Before

A mix of functions, syntax and XP core functionality 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

After

Anything that works as a parameter, property or return type can be used with the is operator.

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

Installation

After installing the XP Compiler into your project, also include this plugin.

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

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

No further action is required.

See also