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

From: Date: Sun, 15 Mar 2020 17:20:11 +0000
Subject: Re: RFC idea: Block scoped variables with "let $x = expr"
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-109031@lists.php.net to get a copy of this message
Am 15.03.2020 um 17:47 schrieb tyson andre <tysonandre775@hotmail.com>: > { > let $myObject = new MyClass(), $flag = 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

« previous php.internals (#109031) next »