Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117417 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18966 invoked from network); 24 Mar 2022 15:08:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Mar 2022 15:08:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D4A8E18053E for ; Thu, 24 Mar 2022 09:35:06 -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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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: Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 ; Thu, 24 Mar 2022 09:35:06 -0700 (PDT) Received: by mail-ej1-f54.google.com with SMTP id dr20so10287968ejc.6 for ; Thu, 24 Mar 2022 09:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NDOJeq50zlYzpWtAecbdocwwrrJ5XwcBTJK4dDF7D+4=; b=RLgcf747/YiiJik15hrbdlsRd5VUAcigJk18+fmiz9PasiYY1K6girm46qgIH8b9mO Bjxm9b3J+OMKhkYj6EVWY51L2JJXw79RQZB6yos/7A+wfCShEM1dNgWxsZcrLqA7E9CV FaFYGccGg3Zm4/8gnSmNrgcp6faIdyhbZhkiDvM7YccIVV6TbTUUXioyh0eQdobF0Hh9 ICiByzf8+2lNiGdErpYX4zhQiiqEF8dLgMDFfvw9S/RKxI44thyRvYHCJ/cBniSlGtkT J5CaM2tx+T0h0DVJiErOUbWRpu/bdPasptLNQSskAUmFpOnNoR2+LCW/l7uDl7wtSy4E CobA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NDOJeq50zlYzpWtAecbdocwwrrJ5XwcBTJK4dDF7D+4=; b=ecUQAaS81H8dGG6m4xuRmCYcvUkY2WbvhFCs5skAYRWj1+K6kZ0Q547oOpJJunqh4d 2mMGI25imErGzTceA/R8aGEVOikowDVdFf6HNb9NBndxipgZkK02GpBHNgn6UsKzE0gQ GDnR6Kv2fMdLjGF7L4wnDS6v1BUidyYv6feP2l801ljyYPYkbD8o3l/qtKtNbKwqovQa hs8Qo8d1O1Hf47IF//4kGtXPd3wg8TySEZT5JILTFx1J7IA0pUIpWuLEDBh45ZcS9Kq2 UNj8+h4RwakGDVv8uUSLZFhr7mbCFM07t1WNVLTp5y4WrBWgB/Cqd6Cw/D3cn13Gpql4 9qiQ== X-Gm-Message-State: AOAM530HwmkH1kjE7fTpW4V4MlXjXIphN9h/g2IO5HTWVjIX0ReTemfQ Qz4wcZ/0YSku3IsDGBPvsA5t0WZ1DOEBlQgwbCTfaexorDo= X-Google-Smtp-Source: ABdhPJxYAXwVUDYAXLexAAMO1M0xCpc/pcVwow3n9eje8K88I7bc95sPpoZVLqWyG3nKlW4i4WRziud4Z6fgfBaG7LM= X-Received: by 2002:a17:907:7ea7:b0:6df:fb36:e8af with SMTP id qb39-20020a1709077ea700b006dffb36e8afmr6761311ejc.356.1648139704773; Thu, 24 Mar 2022 09:35:04 -0700 (PDT) MIME-Version: 1.0 References: <76c399cb-fb29-4583-a212-8eb69740c96b@www.fastmail.com> <95fb2485-fa60-a107-5fd2-acdcef09bca3@processus.org> <2abc84a5-0ca2-9431-0585-d3d6ee3df456@processus.org> In-Reply-To: <2abc84a5-0ca2-9431-0585-d3d6ee3df456@processus.org> Date: Thu, 24 Mar 2022 10:34:53 -0600 Message-ID: To: Pierre Cc: Larry Garfield , php internals Content-Type: multipart/alternative; boundary="000000000000a4b68205daf96dcf" Subject: Re: [PHP-DEV] Typed constants revisited From: mbniebergall@gmail.com (Mark Niebergall) --000000000000a4b68205daf96dcf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Pierre, On Thu, Mar 24, 2022 at 9:20 AM Pierre wrote: > Le 24/03/2022 =C3=A0 16:06, Mark Niebergall a =C3=A9crit : > > So you are correct, the const value does have a value that has a type, > but > > there is no way to enforce which type the value is or to use const with > > inheritance, which is part of the bigger picture here. > > That was exactly my point: the type could simply implicitely be the one > of the original value. > > Then the engine just has to use the existing covariance/contravariance > rules for type checks based upon the guessed value type. This would fix > the type safety issue you are referring to. > I'd rather not use the "guessed value type" in code, that tends to lead to bugs: guessing =3D bugs. Explicitly declaring the type avoids the pitfalls = of guessing and ensures code predictability. It also comes with added benefits, including self-documenting code, defined inheritance requirements (the way you describe would have BC breakage), and (for some IDEs) type hinting. Of note, many other languages already have typed constants. Yes this is the "everyone else is doing it" argument, but they had their valid reasons. Some are strong typed languages, others are not. See: - Go: https://go.dev/blog/constants - HVVM: https://docs.hhvm.com/hack/classes/type-constants - C: https://fresh2refresh.com/c-programming/c-constants/ - C++: https://en.cppreference.com/w/c/language/const - C#: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/= const > > -- > > Regards > > --000000000000a4b68205daf96dcf--