rfc:isset_ternary

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
Last revisionBoth sides next revision
rfc:isset_ternary [2014/09/23 16:39] – Angle brackets! ajfrfc:isset_ternary [2016/03/13 02:04] – Add Errata section ajf
Line 4: Line 4:
   * Author: Andrea Faulds <ajf@ajf.me>   * Author: Andrea Faulds <ajf@ajf.me>
   * Contributor: Nikita Popov <nikic@php.net> (initial patch)   * Contributor: Nikita Popov <nikic@php.net> (initial patch)
-  * Status: In Voting+  * Status: Implemented (PHP 7)
   * First Published at: http://wiki.php.net/rfc/isset_ternary   * First Published at: http://wiki.php.net/rfc/isset_ternary
  
Line 10: Line 10:
 ===== Introduction ===== ===== Introduction =====
  
-PHP is a web-focussed programming language, so processing user data is a frequent activity. In such processing it is common to check for something's existence, and if it doesn't exist, use a default value. Yet the simplest way to do this, something along the lines of ''<nowiki>isset($_GET['mykey']) ? $_GET['mykey'] : ""</nowiki>'', is unnecessarily cumbersome. The short ternary operator, ''?:'' provides a way to do this much more conveniently: ''<nowiki>$_GET['mykey'] ?: ""</nowiki>''. However, this is not good practise, as if the value does not exist it will raise an ''E_NOTICE''. Because of these issues, some sort of ifsetor() operator or a modification to ''?:'''s behaviour to make this common pattern easier has been a frequent request (See References).+PHP is a web-focussed programming language, so processing user data is a frequent activity. In such processing it is common to check for something's existence, and if it doesn't exist, use a default value. Yet the simplest way to do this, something along the lines of ''<nowiki>isset($_GET['mykey']) ? $_GET['mykey'] : ""</nowiki>'', is unnecessarily cumbersome. The short ternary operator, ''?:'' provides a way to do this much more conveniently: ''<nowiki>$_GET['mykey'] ?: ""</nowiki>''. However, this is not good practice, as if the value does not exist it will raise an ''E_NOTICE''. Because of these issues, some sort of ifsetor() operator or a modification to ''?:'''s behaviour to make this common pattern easier has been a frequent request (See References).
  
 ===== Proposal ===== ===== Proposal =====
Line 73: Line 73:
 As this is a language change, a 2/3 majority is required. A straight Yes/No vote is being held. As this is a language change, a 2/3 majority is required. A straight Yes/No vote is being held.
  
-Voting started on 2014-09-20 and ends 2014-09-27.+Voting started on 2014-09-20 and ended on 2014-09-27.
  
-<doodle title="Approve Null Coalesce Operator RFC and merge patch into master?" auth="ajf" voteType="single" closed="false">+<doodle title="Approve Null Coalesce Operator RFC and merge patch into master?" auth="ajf" voteType="single" closed="true">
    * Yes    * Yes
    * No    * No
Line 81: Line 81:
  
 ===== Implementation ===== ===== Implementation =====
-After the project is implemented, this section should contain  + 
-  - the version(sit was merged to +Merged into master (which will be PHP 7): https://github.com/php/php-src/commit/2d069f640e6cccfa3ba8b1e4f375ade20fb33f64 
-  a link to the git commit(s) + 
-  - a link to the PHP manual entry for the feature+Documented at: http://php.net/manual/en/language.operators.comparison.php
  
 ===== References ===== ===== References =====
Line 105: Line 105:
 ===== Rejected Features ===== ===== Rejected Features =====
 Keep this updated with features that were discussed on the mail lists. Keep this updated with features that were discussed on the mail lists.
 +
 +===== Errata =====
 +
 +The name of this RFC [[http://blog.ajf.me/2015-12-07-poorly-named-rfcs|ought to have been "null coalescing operator", not "null coalesce operator"]].
  
 ===== Changelog ===== ===== Changelog =====
  
 +  * (2016-03-13) Added Errata
   * v0.2.3 - Added short-circuit example   * v0.2.3 - Added short-circuit example
   * v0.2.2 - Added precedence example   * v0.2.2 - Added precedence example
rfc/isset_ternary.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1