Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109031 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54856 invoked from network); 15 Mar 2020 18:58:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2020 18:58:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DD6431804DF for ; Sun, 15 Mar 2020 10:20:14 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS1836 195.49.0.0/17 X-Spam-Virus: No X-Envelope-From: Received: from darkcity.gna.ch (darkcity.gna.ch [195.49.47.11]) (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 ; Sun, 15 Mar 2020 10:20:13 -0700 (PDT) Received: from flatter.home (unknown [IPv6:2a02:120b:c3f7:5090:a952:f651:e892:d8ea]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 1190B6C1518; Sun, 15 Mar 2020 18:20:11 +0100 (CET) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) In-Reply-To: Date: Sun, 15 Mar 2020 18:20:11 +0100 Cc: "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: <38BEBA80-AB6E-484C-A0C4-EF440C27DBD9@cschneid.com> References: To: tyson andre X-Mailer: Apple Mail (2.3608.60.0.2.5) Subject: Re: [PHP-DEV] RFC idea: Block scoped variables with "let $x = expr" From: cschneid@cschneid.com (Christian Schneider) Am 15.03.2020 um 17:47 schrieb tyson andre : > { > let $myObject =3D new MyClass(), $flag =3D true; > $myObject->process($flag); > } > // Accessing or setting $myObject or $flag outside a different let is = an E_COMPILE_ERROR > // because it was declared anywhere else in the function body > // as a let statement > $myObject->doSomething(); What you are suggesting is that a let statement would switch PHP to an = altogether different mode where function-scoped and explicit global = variables were suddenly disallowed and an error within that function (or = only after the let?). What about variables not declared with let, would = they still function normally? That sounds like a bad idea to me as I'd have to look at the whole = function to see if there is a let somewhere to determine the = function's/variable's mode. I think that 'let' would only be feasible in a similar fashion to = JavaScript: The lexically scoped variable disappears as if the whole = block was not there. How complicated something like that would be to implement I cannot judge = and I haven't spent a lot of time thinking about other problems of this = proposal. - Chris