rfc:isset-set-operator

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:isset-set-operator [2013/11/27 22:45] – created 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 14: Line 14:
 ?= Will be a new operator that allows the user to set an unset or falsey variable. This handy operator will help avoid dreaded unset variable notices. ?= Will be a new operator that allows the user to set an unset or falsey variable. This handy operator will help avoid dreaded unset variable notices.
  
 +    $foo ?= 'default';
 +    
 +    // which is functionally equivalent to:
 +    $foo = (isset($foo) && $foo) ? $foo : 'default';
 +    
 +    // or
 +    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:
  
-To [[http://news.php.net/php.internals/66051|paraphrase Zeev Suraski]], explain hows the proposal brings substantial value to be considered +    <div class="<?= $user ??'guest' ?>"> ... </div>
-for inclusion in one of the world's most popular programming languages.+
  
-Remember that the RFC contents should be easily reusable in the PHP Documentation. 
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
-What breaks, and what is the justification for it?+Nothing yet.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
  
-List the proposed PHP versions that the feature will be included in.  Use relative versions such as "next PHP 5.x" or "next PHP 5.x.y".+Next PHP 5.x
  
 ===== SAPIs Impacted ===== ===== SAPIs Impacted =====
  
-Describe the impact to CLI, Development web server, embedded PHP etc.+Not yet known.
  
-===== Impact to Existing Extensions =====+===== Open Issues =====
  
-Will existing extensions be affected?+**Possible Alternatives To ?= Operator**
  
-===== New Constants =====+  - ?:= 
 +  - ||= 
 +  - @=
  
-Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation. +**Possible Alternatives To ??: Operator**
- +
-===== php.ini Defaults ===== +
- +
-If there are any php.ini settings then list: +
-  hardcoded default values +
-  php.ini-development values +
-  php.ini-production values +
- +
-===== Open Issues =====+
  
-Make sure there are no open issues when the vote starts!+  - ?:: 
 +  - ?: (backward compatibility concerns) 
 +  - || (backward compatibility concerns) 
 +  - @:
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
  
-List existing areas/features of PHP that will not be changed by the RFC. 
  
-This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise. 
  
 ===== Future Scope ===== ===== Future Scope =====
rfc/isset-set-operator.1385592345.txt.gz · Last modified: 2017/09/22 13:28 (external edit)