Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119476 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33820 invoked from network); 7 Feb 2023 10:30:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Feb 2023 10:30:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4868C18053F for ; Tue, 7 Feb 2023 02:30:54 -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=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE, RCVD_IN_BL_SPAMCOP_NET,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: AS2639 136.143.188.0/23 X-Spam-Virus: No X-Envelope-From: Received: from sender4-op-o12.zoho.com (sender4-op-o12.zoho.com [136.143.188.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 7 Feb 2023 02:30:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675765850; cv=none; d=zohomail.com; s=zohoarc; b=Va9oP3XqpIxbBNEmuJGCUXUp8Wfky8lajlySAtuQBnaAyUSnPUurrb63qhc3e7Ge0ESN2I+xNX2/S4qdDPzEowUfNOk9asKz1AiQDpSa3pIIonfrN7NZ9k11qiOCTRhfHg4JkXAF3Ms+5L8+mMoS1suj+2Gu51w+U4GJPrNefQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675765850; h=Content-Type:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=2eq+EFeD2PHJpWY/aQ70bAl/4cDwkSKiNZ0kOrQaosY=; b=nAm6YEz1jFSK+LLFY7vEhJztDzTzQCqgY7tMQxoNW3g9yvQv7ouAJIe4xHafBVRzVKeibudjhRoLKBbS/a/y9DG+/hanbRT+V+rCkCNcj5c27W+SKXTWCCMrv8OvoIWpcQE5kI20V/o0RhaunhIyQhCUmzUNokED10SQPRxyWjo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=wendelladriel.com; spf=pass smtp.mailfrom=me@wendelladriel.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1675765850; s=admin; d=wendelladriel.com; i=me@wendelladriel.com; h=Date:Date:From:From:To:To:Message-Id:Message-Id:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Reply-To:Cc; bh=2eq+EFeD2PHJpWY/aQ70bAl/4cDwkSKiNZ0kOrQaosY=; b=XBSbl6dMe7CJftanzSOXsCOofgbJqRl4D/MmY49hjhiR1F5zHbp3CCtPAzl4D1tn gnKJFAd6e7Oe2AYfRR4hGaqz++5hhFAdDTjRxqeVgU+p8vzAu/boikyGfmI0/zfCOKW pPbfnKQHPDj63RgB/nmLofceGGW3/fA9uvu45HWU= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1675765849359468.2461962548107; Tue, 7 Feb 2023 02:30:49 -0800 (PST) Date: Tue, 07 Feb 2023 10:30:49 +0000 To: "internals" Message-ID: <1862b6d9cfc.ff3eadd724850.910995154274377639@wendelladriel.com> In-Reply-To: References: <18627e9c82d.1185ba82a2669697.6762525826203739336@wendelladriel.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_80760_1228538917.1675765849340" Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Subject: Re: [PHP-DEV] RFC Proposal - Types for Inline Variables From: me@wendelladriel.com (Wendell Adriel) ------=_Part_80760_1228538917.1675765849340 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey, thanks for the feedback Illia and Hans. Illia, I think that the main motivation for having the support of typing in= line variables is that with that we can have more safety in the code. The code can be more shielded from bugs and easier to maintain. I don't dislike the idea of having something like const on JS, but I think = that adding the support to add types to inline variables at least IMO is a = step further on all the typing that was already added in the language. We have today the ability to add types to function arguments, return and in= class properties. So this is just another step towards adding support to o= ptional typing on another place. Types can bring more confidence when writing code, you can see that for exa= mple a lot of people in the JS community is now using TypeScript because of= the types. I love that PHP already added type support to a lot of places and adding th= e support for typing inline variables would be a game changer for the langu= age I think. Hans, you sent a good example. I think that in this case, it should throw a TypeError, yes. I know this would add a lot of breaking changes. But if we want to avoid some breaking changes we for example make use of th= e declare(strict_types=3D1) to enforce this if this would means in less bre= aking changes. --- Best Regards, Wendell Adriel. Software Engineer=C2=A0| Investor | Amateur Photographer | Musician | INFP= =E2=80=8B https://wendelladriel.com ---- On Tue, 07 Feb 2023 08:34:07 +0000 Hans Henrik Bergan wrote --- function f(int $value){=20 $value=3D"foo"; // should this be a TypeError? BC break all the things=20 }=20 =20 On Mon, 6 Feb 2023 at 22:15, someniatko wrote= :=20 >=20 > Hi there,=20 >=20 > I am not a core PHP language developer, just a regular PHP programmer, an= d=20 > cannot speak for the whole community, so I'll just share my opinion.=20 >=20 > I believe a new language feature suggestion should contain not only its= =20 > description, but also motivation: i.e. what are we trying to achieve with= =20 > it. Will the development experience be worse without it, or maybe it=20 > disallows some sneaky bugs to appear in your code, or maybe it acts as a= =20 > native documentation for your code etc.=20 >=20 > Personally it's hard for me to see what kind of improvement will=20 > restricting a type of a variable bring. It may prevent repurposing the=20 > variable with the same name for a different use somewhere down the=20 > function, which can lead to bugs if a function is large enough. However,= =20 > for such cases I think better idea would be to introduce `const` variable= s=20 > like in JavaScript - which can only be set once and cannot be reassigned= =20 > later. This way you'll also guarantee the type of the variable will be=20 > preserved.=20 >=20 > > We can add types in a lot of places, but we still don't have a way to a= dd=20 > types to inline variables.=20 >=20 > > int $value =3D 10;=20 > > $value =3D 'foo'; // TypeError=20 >=20 > Can you describe some use cases where this feature will be useful? I see= =20 > it's coming from statically typed / compiled languages like C++, but in= =20 > such languages compiler must know variable type in order to manage memory= =20 > properly. As PHP is an interpreted language, it doesn't have this proble= m.=20 >=20 > Regards,=20 > Illia / someniatko=20 =20 --=20 PHP Internals - PHP Runtime Development Mailing List=20 To unsubscribe, visit: https://www.php.net/unsub.php ------=_Part_80760_1228538917.1675765849340--