https://github.com/xp-lang/php-is-operator
Is operator for PHP
https://github.com/xp-lang/php-is-operator
compiler-plugin is-operator php7 php8 xp-compiler xp-framework
Last synced: 14 days ago
JSON representation
Is operator for PHP
- Host: GitHub
- URL: https://github.com/xp-lang/php-is-operator
- Owner: xp-lang
- Created: 2019-09-09T18:12:25.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-05T13:41:30.000Z (9 months ago)
- Last Synced: 2025-04-13T19:53:17.835Z (2 months ago)
- Topics: compiler-plugin, is-operator, php7, php8, xp-compiler, xp-framework
- Language: PHP
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
Is operator for PHP
===================[](https://github.com/xp-lang/php-is-operator/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)
[](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.
Before
------
A mix of functions, syntax and XP core functionality `is()`:```php
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.```php
$value is string
$value is callable
$value is iterable
$value is Date
$value is ?int
$value is array
$value is string|URI
```Installation
------------
After installing the XP Compiler into your project, also include this plugin.```bash
$ composer require xp-framework/compiler
# ...$ composer require xp-lang/php-is-operator
# ...
```No further action is required.
See also
--------
* https://wiki.php.net/rfc/pattern-matching
* https://docs.hhvm.com/hack/expressions-and-operators/is
* https://kotlinlang.org/docs/reference/typecasts.html
* https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/is
* https://externals.io/message/120655 (Proposal to introduce is operator)