PHPackages                             xp-lang/php-is-operator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xp-lang/php-is-operator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xp-lang/php-is-operator
=======================

Is operator for PHP

v3.0.0(1w ago)151[1 PRs](https://github.com/xp-lang/php-is-operator/pulls)BSD-3-ClausePHPPHP &gt;=7.4.0CI passing

Since Sep 9Pushed 1w ago2 watchersCompare

[ Source](https://github.com/xp-lang/php-is-operator)[ Packagist](https://packagist.org/packages/xp-lang/php-is-operator)[ Docs](http://xp-framework.net/)[ RSS](/packages/xp-lang-php-is-operator/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (7)Versions (13)Used By (0)

Is operator for PHP
===================

[](#is-operator-for-php)

[![Build status on GitHub](https://github.com/xp-lang/php-is-operator/workflows/Tests/badge.svg)](https://github.com/xp-lang/php-is-operator/actions)[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)[![Latest Stable Version](https://camo.githubusercontent.com/868418037f9a8594c139f0c4ba52317b67c5e368eee5809a07a4b5e9af777f9f/68747470733a2f2f706f7365722e707567782e6f72672f78702d6c616e672f7068702d69732d6f70657261746f722f76657273696f6e2e737667)](https://packagist.org/packages/xp-lang/php-is-operator)

Plugin for the [XP Compiler](https://github.com/xp-framework/compiler/) which adds an `is` operator to the PHP language compatible with the [PHP pattern matching RFC](https://wiki.php.net/rfc/pattern-matching).

Before
------

[](#before)

A mix of operators, 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
-----

[](#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
$value is string|URI
```

Literal patterns
----------------

[](#literal-patterns)

Tests using the identity comparison:

```
$value is 'test';
$value is 5;
$value is 3|5|null;
$value is 'heart'|'spade';
$value is self::Wild;
$value is 'heart'|'spade'|self::Wild;
```

Numeric comparison patterns
---------------------------

[](#numeric-comparison-patterns)

With greater than (or equal) as well as less than (or equal) operators.

```
$value is =5;
$value is >5 & 0);     // Matches any Point whose $x property is greater than 0
```

Arrays:

```
$value is [1, 2, 3, 4];     // Exact match
$value is [1, 2, 3, ...];   // Begins with 1, 2, 3, but may have other entries
$value is [1, 2, mixed, 4]; // Allows any value in the 3rd position
$value is [1, 2, 3|4, 5];   // 3rd value may be 3 or 4
```

Maps:

```
$value is ['a' => 'A', 'b' => 'B']; // Exact key/value match, but order doesn't matter
$value is ['b' => 'B', ...];        // Must have a 'b' key with value 'B', and more
$value is ['b' => mixed, ...];      // Must have a 'b' key with any value, and more
```

Capturing values
----------------

[](#capturing-values)

Binding variables to object properties as well as array and map values:

```
$value is Point(x: 3, y: $y);           // If $p->x === 3, bind $p->y to $y
$value is ['a' => 'A', 'b' => $b];      // Bind value of key 'b' to $b
$value is ['op' => 'drop', ... $items]; // Bind rest of array to $items
```

Match statement
---------------

[](#match-statement)

The operator can be used in the cases of a *match* statement:

```
$result= match ($value) {
  is int    => $value,
  is string => '"'.strtr($value, ['"' => '\\"']).'"',
  null      => 'null',
};
```

Installation
------------

[](#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
--------

[](#see-also)

-
-
-
-
-  (Proposal to introduce is operator)

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance98

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~270 days

Recently: every ~415 days

Total

10

Last Release

7d ago

Major Versions

v0.1.0 → v1.0.02019-11-30

v1.1.2 → v2.0.02024-03-24

v2.1.0 → v3.0.02026-05-10

PHP version history (3 changes)v0.1.0PHP &gt;=5.6.0

v1.0.0PHP &gt;=7.0.0

v2.0.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/07d18d882c8b4aaf3466432f64018214f2771eda333202175431ee7233795376?d=identicon)[thekid](/maintainers/thekid)

---

Top Contributors

[![thekid](https://avatars.githubusercontent.com/u/696742?v=4)](https://github.com/thekid "thekid (76 commits)")

---

Tags

compiler-pluginis-operatorphp7php8xp-compilerxp-frameworklanguagemodulexp

### Embed Badge

![Health badge](/badges/xp-lang-php-is-operator/health.svg)

```
[![Health](https://phpackages.com/badges/xp-lang-php-is-operator/health.svg)](https://phpackages.com/packages/xp-lang-php-is-operator)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
