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

From: Date: Tue, 13 Oct 2020 08:41:14 +0000
Subject: Req #80222 [Com]: Operator for !empty() - analog of `??`
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229592@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 Comment by: somerussian at ya dot ru Reported by: somerussian at ya dot ru Summary: Operator for !empty() - analog of ?? Status: Suspended Type: Feature/Change Request Package: *General Issues PHP Version: Next Minor Version Block user comment: N Private report: N New Comment: Thanks for reply guys. Maybe we can refactor the ?: operator then? I mean this line: <?php $a = $b ?: 0; ?> could work like this: <?php $a = !empty($b) ? $b : 0; ?> and it makes much more sense then this: <?php $a = $b ? $b : 0; ?> Previous Comments: ------------------------------------------------------------------------ [2020-10-12 11:25:58] cmb@php.net This feature is obviously controversial and as such requires the RFC process[1]. Feel free to start it. For the time being, I'm suspending this ticket. [1] <https://wiki.php.net/rfc/howto> ------------------------------------------------------------------------ [2020-10-12 11:17:10] nikic@php.net 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. ------------------------------------------------------------------------ [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 (#229592) next »