[Proposal] Introduce is operator
| From: | Удальцов Валентин | Date: | Wed, 21 Jun 2023 22:44:25 +0000 |
| Subject: | [Proposal] Introduce is operator | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-120655@lists.php.net to get a copy of this message | ||
Hi internals,
Today PHP is more typed than ever, however, one feature is still missing:
ability to check complex variable types using standard type declarations.
For example, to check that $var is a nullable string one has to do
assert($var === null || is_string($var)). To check that $var is false or
a countable iterator, one has to write `assert($var === false || ($var
instanceof Countable && $var instanceof Iterator))`.
I propose to add a new "is" operator that allows to have `assert($var is
?string) and assert($var is false|(Countable&Iterator))`. So it is
similar to instanceof, but accepts any valid PHP type declaration on the
right side.
WDYT?
Regards,
Valentin