[Proposal] Modification to ?: functionality
| From: | Chris London | Date: | Tue, 26 Nov 2013 14:43:12 +0000 |
| Subject: | [Proposal] Modification to ?: functionality | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-70402@lists.php.net to get a copy of this message | ||
I find in a lot of my code I have ternaries that set default values. I
also find that I can't use the ?: syntax for one reason and one reason
only. It throws a notice if the value isn't set.
I believe these two statements are functionally equivalent:
$foo = $foo ? $foo : 'default';
$foo = $foo ?: 'default';
I would like to change it so it also checks for isset() so I propose the
following would be functionally equivalent:
$foo = isset($foo) && $foo ? $foo : 'default';
$foo = $foo ?: 'default';
Random addition: what if we also allowed the following shorthand?
$foo ?= 'default';
or possibly:
$foo ?:= 'default';
Thanks everyone,
Chris