#45320 [Opn->Bgs]: Ternary-Operator Shortcut and empty()
| From: | colder@php.net | Date: | Fri, 20 Jun 2008 10:13:26 +0000 |
| Subject: | #45320 [Opn->Bgs]: Ternary-Operator Shortcut and empty() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-125915@lists.php.net to get a copy of this message | ||
ID: 45320
Updated by: colder@php.net
Reported By: reto at buxaprojects dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
PHP Version: 6CVS-2008-06-20 (snap)
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
$a ?: $b; is equivalent to $a ? $a : $b;
so in your code:
!empty($var) ?: 'Nothing'
is equivalent to :
!empty($var) ? !empty($var) : 'Nothing';
and not
!empty($var) ? $var : 'Nothing';
Previous Comments:
------------------------------------------------------------------------
[2008-06-20 08:12:27] reto at buxaprojects dot com
Description:
------------
The Ternary-Operator shortcut doesn't do the same with empty()
Reproduce code:
---------------
ini_set('display_errors', true);
error_reporting(E_ALL|E_STRICT);
$var = 'Something';
echo !empty($var) ? $var : 'Nothing';
echo !empty($var) ?: 'Nothing';
Expected result:
----------------
SomethingSomething
Actual result:
--------------
Something1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45320&edit=1