rfc:isset-set-operator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:isset-set-operator [2013/11/30 16:05] chrislondonrfc:isset-set-operator [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 4: Line 4:
   * Date: 2013-11-24   * Date: 2013-11-24
   * Author: Chris London, me chrislondon co   * Author: Chris London, me chrislondon co
-  * Status: Draft+  * Status: Draft (Inactive)
  
 ===== Introduction ===== ===== Introduction =====
Line 20: Line 20:
          
     // or     // or
-    if (!isset($foo) && !$foo) $foo = 'default';+    if (!isset($foo) || !$foo) $foo = 'default'; 
 + 
 +??: will be equivalent to the ternary short hand ?: except that it also checks for isset(). 
 + 
 +    // $bar is unset 
 +     
 +    $foo = $bar ?: 'other'; // Throws undefined notice 
 +     
 +    $foo = $bar ??: 'other'; // Does NOT throw undefined notice 
 +     
 +    // ??: is functionally equivalent to: 
 +    $foo = (isset($bar) && $foo) ? $bar : $other; 
 +     
 +This will be very helpful for echoing default variables in HTML like so: 
 + 
 +    <div class="<?= $user ??: 'guest' ?>"> ... </div>
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 36: Line 51:
 ===== Open Issues ===== ===== Open Issues =====
  
-To be added+**Possible Alternatives To ?= Operator** 
 + 
 +  - ?:= 
 +  - ||= 
 +  - @= 
 + 
 +**Possible Alternatives To ??: Operator** 
 + 
 +  - ?:: 
 +  - ?: (backward compatibility concerns) 
 +  - || (backward compatibility concerns) 
 +  - @:
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
rfc/isset-set-operator.1385827521.txt.gz · Last modified: 2017/09/22 13:28 (external edit)