On 13/12/2022 16:08, Dan Liebner wrote:
Can I also just point out that by current definitions the "null coalescing
operator" isn't properly named, it should be the "undefined/null coalescing
operator". The only reason it is able to get away with not raising an error
for undefined variables is that it's described as "syntactic sugar" for
isset(), which is itself the exception to the rule for not raising
undefined errors.Other languages, such as JavaScript, would raise an error
for an expression such as `undefinedvar ?? 0`. And JavaScript conveniently
offers the undefined primitive for precisely handling attempted accesses of
undefined keys, while retaining the brevity and convenience of a
truthy/falsy `obj.key` check.


Can you expand a bit on how you think distinguishing "undefined" from "null" would help? Let's keep the focus on possible solutions, not just arguing in circles.

It's always been a source of confusion to me that JS has both, and the syntax for working them seems far from elegant (unless things have improved, and you no longer need to use typeof to detect undefined?); but maybe I'm looking at it wrong.

Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to