Req #80222 [Opn]: Operator for !empty() - analog of `??`

From: Date: Mon, 12 Oct 2020 11:17:10 +0000
Subject: Req #80222 [Opn]: Operator for !empty() - analog of `??`
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229563@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80222&edit=1 ID: 80222 Updated by: nikic@php.net Reported by: somerussian at ya dot ru Summary: Operator for !empty() - analog of ?? Status: Open Type: Feature/Change Request Package: *General Issues PHP Version: Next Minor Version Block user comment: N Private report: N New Comment: I think this addition is not very likely. We already have ?:, ?? and ?-> to keep apart, at some point we cannot add new operators for every possible coalescing operation that could be useful in some circumstance. Previous Comments: ------------------------------------------------------------------------ [2020-10-12 11:06:26] somerussian at ya dot ru Description: ------------ There is already a Null Coalescing Operator (kind of a shortcut for isset()), which is very handy, because it allows write less and do more. So 2 lines in the example below would do the same: <?php $name = isset($data['name']) ? $data['name'] : 'noname'; $name = $data['name'] ?? 'noname'; ?> But it's also would be great to have similar operator for !empty(), e.g: <?php $name = !empty($data['name']) ? $data['name'] : 'noname'; $name = $data['name'] ??? 'noname'; ?> Not sure about the symbols for that new operator: ??? ?! !e (?) any other I miss this feature very much, and I guess lot's of people can't wait for it too. Is there a chance that we would have Empty Coalescing Operator in the next version of PHP? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80222&edit=1

« previous php.bugs (#229563) next »