Req #62043 [NEW]: new operator
| From: | piotrekz5 at wp dot pl | Date: | Tue, 15 May 2012 23:23:20 +0000 |
| Subject: | Req #62043 [NEW]: new operator | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-170487@lists.php.net to get a copy of this message | ||
From:
Operating system: any
PHP version: Irrelevant
Package: PHP options/info functions
Bug Type: Feature/Change Request
Bug description:new operator
Description:
------------
Hi,
Let's implement a new operator - '??' (used in c#).
The ?? operator is called the null-coalescing operator and is used to
define a default value. It returns the left-hand operand if the operand is
not null; otherwise it returns the right operand.
Test script:
---------------
example:
$var1 = null;
$var2 = null;
$var3 = $var1 ?? $var2; //$var3==null
$var4 = $var1 ?? 'default1'; //$var4=='default1'
$var5 = $var1 ?? $var2 ?? 'default2'; //$var5=='default2'
$var6 = $var2 ?? $var3 ?? $var4 ?? 'default3'; //$var6=='default1' since
the first non-null value is $var4=='default1'
--
Edit bug report at https://bugs.php.net/bug.php?id=62043&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62043&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62043&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62043&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=62043&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62043&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=62043&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=62043&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=62043&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=62043&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=62043&r=support
Expected behavior: https://bugs.php.net/fix.php?id=62043&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=62043&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=62043&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=62043&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62043&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62043&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=62043&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=62043&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=62043&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=62043&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=62043&r=mysqlcfg