Re: RFC idea: Block scoped variables with "let $x = expr"

From: Date: Sun, 15 Mar 2020 17:42:40 +0000
Subject: Re: RFC idea: Block scoped variables with "let $x = expr"
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-109032@lists.php.net to get a copy of this message
> 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?).  No, the variables with the *same name* as the variables in any "let" in that function body would be disallowed. In this proposal, variables, parameters, and closure uses with different names can be declared and used normally. I mentioned $GLOBALS as one of the ways in which this proposal is a best-effort. However, I'm not proposing to ban $GLOBALS (but to ban $$var). - The top-level statements of the file can either be the global variables or the variables in the function which required the file. It's not known which at compile time, so I don't plan to ban $GLOBALS. > 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. A developer would run php --syntax-check to know if the variable is being accessed incorrectly in a file. Various tools or scripts exist to do that, in Continuous Integration or in editors/IDEs. If you meant something else, could you give a code example? - Tyson

« previous php.internals (#109032) next »