Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114851 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99978 invoked from network); 14 Jun 2021 07:10:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jun 2021 07:10:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F10CD1804D1 for ; Mon, 14 Jun 2021 00:26:37 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 14 Jun 2021 00:26:37 -0700 (PDT) Received: by mail-wm1-f41.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso12260199wmh.4 for ; Mon, 14 Jun 2021 00:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=k+tWYRFrpys2C7jzkSssz/NnarfFOymOgk8L0R6DcmA=; b=Ns3U/F+7mesZeXiJ9VNX2LP4eO539zjPyLKFxizDb2D9Daxa3uH+6Dd5s897GUPcQq 8BZsAoKHfahvZYX8gkDLYJt5x3a+hVEkMxbLBl/hTwWBPmprJHr7ZkdAiLdBZ8CRR3Xc x/HPUlReS6pn2ySk6tcNXusDMQO1s1n88/8EC0MfCUF759t8s95/aK/TFujD0HnyH6wJ 4O1wKRi6ozoutVT5UCtd+MtB7QmXUTSdimqO8LDo9AH/kq9xZNxDDma3fXflOsTuyllR vr+pws6IIvlDxOVX+7KMrhaKOV4IyXqhdw/J5vmGL1bD/uKiy1mcIt7hhmUdJeCX3hzN UrRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=k+tWYRFrpys2C7jzkSssz/NnarfFOymOgk8L0R6DcmA=; b=KsE9UaEmkOZUTpqPXRO0OCw0rjCA/6UbmDqd+xXcm2nN1KUccdMSFl5fdbo/Me5GgF SXhZTitS+aaSmWEoENd9wvktp3+VyF2HyRC7bhGPlUp6h4oS5u+L+kkBOh6Dl0axLN5+ QYxQL/ojy5mMPZSgD6JRRfDbT0GIrRWfIWaMVZVDGofe6nKEfqKb8+H8ojClhNd3bjQ1 q6itwK3taj+EKMtssNCrXKKMhxEECwnsIozf2GtBXU80idPDmiwBe1U0Jaa13ds5Wa2S ieH8ADhX9hvg85kbF2lpV9KhwlB6ay/0dU7IQsMD2/0NrjusMzL1m4EyS/8JCDfC54XB HD5Q== X-Gm-Message-State: AOAM532Ey9yJQoEGwRKsQlWZ04xej6ddv06SjA//kBXhc4QkQI9wk0Rs HHXJkkUmO2A47oYnMJC0rUu7fNYL8FiF1XIbxXcAFpPxOniWfg== X-Google-Smtp-Source: ABdhPJynoRSHcCRtCwkM7NL1J5Ueq3A7vH9Ba3Z5bmSxdSdIr02u2CkqTZtAqKl+5Ye64vqUiQcloggW/OKKvjXlYrM= X-Received: by 2002:a7b:c346:: with SMTP id l6mr14541240wmj.109.1623655593889; Mon, 14 Jun 2021 00:26:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 14 Jun 2021 10:26:21 +0300 Message-ID: To: Craig Francis Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] is_literal From: someniatko@gmail.com (someniatko) > And I agree, there would be value in having a `literal-string` type, espe= cially when working with IDE's and Static Analysers; but it brings a couple= of issues that the is_literal() function solves: Yeah, those are valid arguments why we should have a dedicated `is_literal()` function, and in fact we could have both the type and the function at the same time, the same as we have `string` type and `is_string()` function. My worry is, if type is not added in the present RFC, adding it later may look as "too low value" and probably will have a lower chance of being accepted. > 1) Libraries need to support older versions of PHP, so they wouldn't be a= ble to use the `literal-string` for many years; whereas they can use `funct= ion_exists('is_literal')` today, probably to provide their own function tha= t simply returns true on pre PHP 8.1. If the type is added in say 8.2, they wouldn't be able to use it even longer. Of course this can be re-modelled using a value object which performs the is_literal() check in the constructor, however I think a native PHP type would be better, for example in the case of variance checks (being a subtype of "string"). > 2) The is_literal() function gives the libraries a choice on how to handl= e the situation. At the moment they just receive a string of unknown origin= , so they can trigger a warning, while also supporting legacy projects who = want to switch off the warnings. And some developers might want to use a li= brary that has an option that can raise exceptions (so they can be certain = there are no issues). If we have both the fn and the type, libraries would still have that choice, either enforce it solidly and throw TypeError (PHP 8.1), or polyfill the `is_literal()` function to always return `true` and be able to both take advantage of PHP 8.1 and work on the earlier versions. I hope these points will be really considered, and PHP's type system will evolve into more robust and strong one. (offtopic: hoping we will have typed vector and dict types someday too) > Craig Regards, someniatko