Req #75833 [Opn->Sus]: Improve null-coalescing operator (??) adding empty check (??:)
| From: | requinix@php.net | Date: | Wed, 17 Jan 2018 13:36:53 +0000 |
| Subject: | Req #75833 [Opn->Sus]: Improve null-coalescing operator (??) adding empty check (??:) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213587@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75833&edit=1
ID: 75833
Updated by: requinix@php.net
Reported by: lito at eordes dot com
Summary: Improve null-coalescing operator (??) adding empty
check (??:)
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: PHP Language Specification
+Package: *General Issues
Operating System: All
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Thank you for your interest in PHP and for submitting a feature
request. Please be aware that due to the magnitude of change this
request requires, it would be necessary to discuss it on PHP
Internals list (internals@lists.php.net) as an RFC. Please read
the guide about creating RFCs here:
<https://wiki.php.net/rfc/howto>. If you
haven't had experience
with writing RFCs before, it is advised to seek guidance on the
Internals list (<http://php.net/mailing-lists.php>) and/or solicit
help from one of the experienced developers.
Please do not consider this comment as a negative view on the
merits of your proposal â every proposal which requires changes of
certain magnitude, even the very successful and widely supported
ones, must be done through the RFC process. This helps make the
process predictable, transparent and accessible to all developers.
Previous Comments:
------------------------------------------------------------------------
[2018-01-17 13:28:35] lito at eordes dot com
Description:
------------
From PHP 7 null-coalescing operator is a great option to avoid a previous exists check with isset.
But I think that this comaparison can be improved adding a ternary operator like ??: and check also
empty values.
Check example into text script section.
Test script:
---------------
<?php
$foo = '';
// Current response with null-coalescing operator
echo $foo ?? 'default'; // ''
// Possible response with ternary null-coalescing operator
echo $foo ??: 'default'; // 'defaut'
// Same response with current available PHP code
echo (isset($foo) && $foo) ? $foo : 'default'; // 'default'
$foo = false;
// Current response with null-coalescing operator
echo $foo ?? 'default'; // false
// Possible response with ternary null-coalescing operator
echo $foo ??: 'default'; // 'defaut'
// Same response with current available PHP code
echo (isset($foo) && $foo) ? $foo : 'default'; // 'default'
$foo = null;
// Current response with null-coalescing operator
echo $foo ?? 'default'; // 'defaut'
// Possible response with ternary null-coalescing operator
echo $foo ??: 'default'; // 'defaut'
// Same response with current available PHP code
echo (isset($foo) && $foo) ? $foo : 'default'; // 'default'
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75833&edit=1