On 10/09/2017 20:16, Theodore Brown wrote:
On Sunday, September 10, 2017 12:45 PM Rowan Collins
<rowan.coll...@gmail.com> wrote:
>>> Would it be possible to add an optional `$strict` parameter to
>>> switch? E.g.
>>> ```
>>> switch ($i, true) {
>>
>> I'd very much prefer a "strict switch ($i) { ... }" over a second
parameter.
>
> What do either of you think of my "switch-use" proposal, which would
spell this as "switch ($i) use (===)"?
That seems more complicated and confusing than either of the other
options. Normally `use()` is for inheriting variables in anonymous
functions.
The choice of "use" as the keyword was largely because it's already a
reserved word, with multiple meanings in different contexts. As well as
anonymous functions, it's the keyword for importing names from other
namespaces, and for including a trait into a class. I would be perfectly
happy to hear alternative keyword or syntax suggestions.
It might not need a keyword at all, as it could just be "switch ($i ===)
{ ... }" or "switch ($i) === { ... }", although I'm not that keen on
either of those.
However, I think using "===" in some form is definitely clearer than ",
true", which could mean anything; and even "strict" could have multiple
meanings - for instance, a "strict switch" might be one where "break"
was mandatory.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php