Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117418 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22865 invoked from network); 24 Mar 2022 16:20:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Mar 2022 16:20:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AEEC9180543 for ; Thu, 24 Mar 2022 10:47:47 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (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 10:47:47 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 836265C0039 for ; Thu, 24 Mar 2022 13:47:46 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Thu, 24 Mar 2022 13:47:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=i/ibdEkYT5z5CpelPgqWXanWNq8sn+uBHsqC9aQqcOg=; b=W9/bdV9T Weh9Z1U2KaA2qSsYdTm3cZ/hfqPnkB4t9c+SO6aKhojhNDSHEDK1BM8KWxXek4dy iqqPQsz/kr/6QYjCNA6WJ/xHy7nW/hT/T9zqlfx+LjUf83k63tJoJg20TG0jTb0R pt02kbCi2EJxVDLQ5i8XJd92bhA6yafgJpySgZmsWRFimNgsqGCtpteognXkLl4w 6B8F1h1sMxMyRLqlQVfA9kCfoNcZ8ySYG608z5r5Bq5IWwOWB465IWUrqm7Qd0Ev HEzMCuR2nEHbZuBy8/BxJHYDb7FdwCYgKSaFY0uAl8h89/Cwf0T8q85YHz9/HjZk CViAjkYjoHeYCA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudegledguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpedtveelhfejffegvdehudduleehveeilefffeeg geeufefhfeejjeegtdejhffgheenucffohhmrghinhepghhordguvghvpdhhhhhvmhdrtg homhdpfhhrvghshhdvrhgvfhhrvghshhdrtghomhdptghpphhrvghfvghrvghntggvrdgt ohhmpdhmihgtrhhoshhofhhtrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4043AAC0E98; Thu, 24 Mar 2022 13:47:46 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4911-g925b585eab-fm-20220323.003-g925b585e Mime-Version: 1.0 Message-ID: <20061f9f-91e1-49e3-b05c-35b2ded09087@www.fastmail.com> In-Reply-To: References: <76c399cb-fb29-4583-a212-8eb69740c96b@www.fastmail.com> <95fb2485-fa60-a107-5fd2-acdcef09bca3@processus.org> <2abc84a5-0ca2-9431-0585-d3d6ee3df456@processus.org> Date: Thu, 24 Mar 2022 12:47:25 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Typed constants revisited From: larry@garfieldtech.com ("Larry Garfield") On Thu, Mar 24, 2022, at 11:34 AM, Mark Niebergall wrote: > Pierre, > > On Thu, Mar 24, 2022 at 9:20 AM Pierre wrot= e: > >> 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 ty= pe, >> 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 o= ne >> 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 f= ix >> the type safety issue you are referring to. >> > > I'd rather not use the "guessed value type" in code, that tends to lea= d to > bugs: guessing =3D bugs. Explicitly declaring the type avoids the pitf= alls of > guessing and ensures code predictability. It also comes with added > benefits, including self-documenting code, defined inheritance require= ments > (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 i= s 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/keyw= ords/const The addition of union types put the kibosh on successfully type guessing= , I think. If you have a const that you'll allow a float or int in, and= the default is 0, the guesser will guess int, not float, and then you c= an't allow a float. So "constant inheritance" is a use case for typed constants, even if con= stant inheritance is a rather edge-case situation to begin with. --Larry Garfield