Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
rfc:isset_ternary [2014/09/27 15:18] – RFC accepted ajf | rfc:isset_ternary [2015/12/24 21:14] – add docs link ajf |
---|
* 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: Accepted | * Status: Implemented (PHP 7) |
* First Published at: http://wiki.php.net/rfc/isset_ternary | * First Published at: http://wiki.php.net/rfc/isset_ternary |
| |
===== 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 ===== |
| |
===== Implementation ===== | ===== Implementation ===== |
After the project is implemented, this section should contain | |
- the version(s) it 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 ===== |