Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120655 Return-Path: <udaltsov.valentin@gmail.com> Delivered-To: mailing list internals@lists.php.net Received: (qmail 17581 invoked from network); 21 Jun 2023 22:44:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Jun 2023 22:44:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2D3A61804C9 for <internals@lists.php.net>; Wed, 21 Jun 2023 15:44:38 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: <udaltsov.valentin@gmail.com> Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for <internals@lists.php.net>; Wed, 21 Jun 2023 15:44:37 -0700 (PDT) Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-3f9c2913133so11629945e9.1 for <internals@lists.php.net>; Wed, 21 Jun 2023 15:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687387476; x=1689979476; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=yuC29kFpl2YfKT6GyTOEIUjwd7FnP9wX+uXJepPoeMY=; b=Z/qDEk0uCQi9TTYczvMVX2UT9oVggxPEe2LeSdMI3+cjgeQzqcfIzGYPoUMksgSqXS 3ioEYuUfzMfRWZHvXvSnZmyAOgW9HvF7QFMYkTdHYTCfKL8PNd9VV1fBo6x673NONJz9 PI86IUl9jyZ3Tt7lYemn6ypMJV3vNXKqVaaD1s2tlWdKtY2DRXvnuCa5+EbWDkUI0yWn qQx7fYusO0wQ+plvYmSdrPKBiGPGasFd/1N9hPtooD5TeaqG6x5b2rDexhSNHyhIwk0d jVDsPr8nBbtxkOR+V4vaVZ8i4H3boVDocpPKg6v5JRJVoOqlXFD/G0m+X+pSrBRy5jqQ EYTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687387476; x=1689979476; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yuC29kFpl2YfKT6GyTOEIUjwd7FnP9wX+uXJepPoeMY=; b=N4lGvnnOsK/1TuPMLxbPMZ8Z2FUeifRZEGKHxW43uRUyA33GDrhvL8hFuKj6J9nBSe A3pWs1NrBuKHwYE30V4jWt8O57IA5UtkruYz7Sk/T4aVfz48yezuN/RpY9cwWKCwtT14 88M92zz2jcsaJBEOXdr5XdU+zfzubcpHmHQ7qEgPnYlWRMpPioInYr3DZrDOPLYLKdA2 DhRZt+Yc4nrSlioIdrJojE7OmTpBXJ3+/L0guxiSrcBGBss+cK1QDEs3Zx70BBxNtDSK ronSfTGXGNJxjQlt+BN8j/+XicAQJmXTMrBMBbJ+MM0MTJkVUewpCGFo15xpMUKg4wi/ 8SRg== X-Gm-Message-State: AC+VfDw7q9b0+Mm0HUbNCraN4uXKTPBnOo0koL94rZa6JxL6BVoirSi+ kDG/V+D3b6u2E27k2NXHlAwppSYyrR0iZSPjPpVrmileu2CXCk4= X-Google-Smtp-Source: ACHHUZ4KU1e3J73E7QthwcYWqQdY99PdnXBiz2G+FSarpMBXhwhFeZVq6D9eMiyfie02jIgDf4MjFtltW7opR9j83ZM= X-Received: by 2002:a7b:cb4e:0:b0:3f7:f884:7be3 with SMTP id v14-20020a7bcb4e000000b003f7f8847be3mr13028408wmj.4.1687387475923; Wed, 21 Jun 2023 15:44:35 -0700 (PDT) MIME-Version: 1.0 Date: Thu, 22 Jun 2023 01:44:25 +0300 Message-ID: <CAPyeZ4OmR8CBfh5VSz6YOhzN6gdkYwBMGak89HyyNQinqDx8eA@mail.gmail.com> To: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000019d7bf05feab83a0" Subject: [Proposal] Introduce is operator From: udaltsov.valentin@gmail.com (=?UTF-8?B?0KPQtNCw0LvRjNGG0L7QsiDQktCw0LvQtdC90YLQuNC9?=) --00000000000019d7bf05feab83a0 Content-Type: text/plain; charset="UTF-8" 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 --00000000000019d7bf05feab83a0--