Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119474 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25046 invoked from network); 7 Feb 2023 08:34:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Feb 2023 08:34:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A230C180340 for ; Tue, 7 Feb 2023 00:34:46 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,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: Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 7 Feb 2023 00:34:46 -0800 (PST) Received: by mail-yb1-f182.google.com with SMTP id q4so12932012ybu.7 for ; Tue, 07 Feb 2023 00:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xifpPUF0Rwgq4BZRKSCYDcmBEbYtALdKdDXxfFlZjME=; b=UwBRD81SyNqI39aPZaYyHEcPl3xa0FfiVx3Fp9RGGBSojdCyiPZBTRid2PLFttR/xF ua/DHEFzaN9CpLLt+4POM5CooyYxlmf2fTUzZSSnajUWfcFiSAjRXv6TDifvgP2/2d3O RXWbJIxhX0k/SnyqW2PQyoMeKB/Eg9hVYvKcGjfHwEoxdvNBYYELfMez/m8Utk4PQOkF H8F477cnvHsqvQbWUGe7538lE6iwxO6ripebFStGgkIg2Kj5YDmcx2AuON2p/mC4sBiP 2EZwuh6B2KIG9DvUtGCdVOUxazvqgmbTRf5FEZsFru9+baGrTkag8Dp0Xylf5Gqa6p1h nw6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xifpPUF0Rwgq4BZRKSCYDcmBEbYtALdKdDXxfFlZjME=; b=r1Z3TGtuWvRpBFsDDTp1tEl8Zvi7PfF4vp7ypNF/6uqxNuXv/d9CINF596Jztt/UHH kMW7vvy5QZxte8hqeXcIrOUFGcqEgAsiMuI4xnoaGOFZGCX9gtvzgsmRANkrRSursE/R jwQAwx5KtMOVaOou9XNRHQrgRKoSinUKGLfA0pPf6WBH6ubndHG/lJseU59hEw0AysaL Va4LtK6EJD/D2i/YCSB1L25nCR9CEH/oOYdw+wZKoBlAi44melbmNYO4z+7jFUmac3Ku G5flTvIlinxUrbtOjNJP5l5RnvXELCZchjr7/lXZup0t5dWaXv9ASdMWPGHJYCQTKexE kVXQ== X-Gm-Message-State: AO0yUKWXDUAwgzRxdlFUG6RY/Fk7nuub7Q9KKY3DMN1ppuHbyvQ2x6cn eXI4NGQmUEV8oQj0AZt5NuQshdvHI3sVjuZ07UI= X-Google-Smtp-Source: AK7set9nbd9wzbetp/IqkISt0aWx+uq0VqLQzVdbVilpqCFWzxlqKRnaRZVx3GawZgdhVPLCJlvBrOKwJkONFa/KimI= X-Received: by 2002:a25:9347:0:b0:855:d2c4:2119 with SMTP id g7-20020a259347000000b00855d2c42119mr363203ybo.107.1675758885475; Tue, 07 Feb 2023 00:34:45 -0800 (PST) MIME-Version: 1.0 References: <18627e9c82d.1185ba82a2669697.6762525826203739336@wendelladriel.com> In-Reply-To: Date: Tue, 7 Feb 2023 09:34:07 +0100 Message-ID: To: someniatko Cc: Wendell Adriel , internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] RFC Proposal - Types for Inline Variables From: divinity76@gmail.com (Hans Henrik Bergan) function f(int $value){ $value="foo"; // should this be a TypeError? BC break all the things } On Mon, 6 Feb 2023 at 22:15, someniatko wrote: > > Hi there, > > I am not a core PHP language developer, just a regular PHP programmer, and > cannot speak for the whole community, so I'll just share my opinion. > > I believe a new language feature suggestion should contain not only its > description, but also motivation: i.e. what are we trying to achieve with > it. Will the development experience be worse without it, or maybe it > disallows some sneaky bugs to appear in your code, or maybe it acts as a > native documentation for your code etc. > > Personally it's hard for me to see what kind of improvement will > restricting a type of a variable bring. It may prevent repurposing the > variable with the same name for a different use somewhere down the > function, which can lead to bugs if a function is large enough. However, > for such cases I think better idea would be to introduce `const` variables > like in JavaScript - which can only be set once and cannot be reassigned > later. This way you'll also guarantee the type of the variable will be > preserved. > > > We can add types in a lot of places, but we still don't have a way to add > types to inline variables. > > > int $value = 10; > > $value = 'foo'; // TypeError > > Can you describe some use cases where this feature will be useful? I see > it's coming from statically typed / compiled languages like C++, but in > such languages compiler must know variable type in order to manage memory > properly. As PHP is an interpreted language, it doesn't have this problem. > > Regards, > Illia / someniatko