Re: [RFC] anti-coalescing-operator
| From: | Rowan Tommins | Date: | Thu, 24 Oct 2019 20:24:16 +0000 |
| Subject: | Re: [RFC] anti-coalescing-operator | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107668@lists.php.net to get a copy of this message | ||
Hi Ken,
This is definitely an interesting idea, and when described as "the opposite of ??" the !?? syntax makes sense.
Looking at the example, though, the "negating" part becomes a bit confusing.
The verbose form reads naturally as a positive assertion - "if this is set, do this":
if (isset($_SERVER['fname']) {
$user->setName($_SERVER['fname']);
}
If we used the ?? operator, it would be a negative, "if this is not set, do this":
So the short-hand form becomes a kind of double negative - "if this is not set, don't do this", or "if this is not not set, do this":$_SERVER['fname'] ?? $user->unsetName();
That makes me think that the choice of syntax isn't quite right, but I'm not sure what to suggest instead. Regards, -- Rowan Tommins (né Collins) [IMSoP]$_SERVER['fname'] !?? $user->setName($_SERVER['fname']);