Hi guys Below is a discussion about some of the issues being raised. Again a nicely formatted version of the whole thing is here: https://gist.github.com/909711.
## Discussion ## ### About changing the beviour of the ternary shortcut ### @Jordi, others Some suggest adding an implicit `isset` around the value being tested in the ternary shortcut. This I think is less than optimal because: 1. It would be a huge BC break, because a boolean test and a isset test differs greatly. [3] 2. It would be a major WTF, because it would work different than the normal ternary operator that it is a shortcut of. Jordi suggests adding an implicit `!empty` around the value being tested in the ternary shortcut. This would not break BC but it still wouldn't improve usecases where the value tested for is allowed to be falsy ('', 0, "0", false, etc.): function render_articles($rows, $settings) { // Shows the last page per default. Zero based. $settings['page_num'] = $settings['page_num'] ?: count($rows) - 1; // ... } // Lets render_articles showing the first page. echo render_articles ($rows, array('page_num' => 0)); The obvious bug here is that since 0 is considered falsy, render_articles will show the last page instead of the first. The correct version is back in non-dry mode: $settings['page_num'] = isset($settings['page_num']) ? $settings['page_num'] : count($rows) - 1; Im writing the same stuff three times. With the `??` operator it would be: $settings['page_num'] ??= count($rows) - 1; ### Why we need both an Isset and IsNotEmpty operator ### @Hannes, Ben What's considered falsy in PHP is _very_ dynamic. Depending on context the following can easily be considered falsy: '', null, undefined, array(), false, 0 Therefore we need to be very precise when we are making decisions based on a variable or statements value. This is where `isset` and `!empty` compliments each other very well. Sometimes i want to use a default value when falsy means "this variable is not defined". Other times I want to assign a default value when falsy means "this variable is not an empty string". Sometimes the behaviour we want will change while we are working on the code. Therefore I strongly believe that not having both operators would severely break the symmetry and force the end user to make tedious and non-dry refactorings just because he needs a function to - under certain conditions - return false or vice versa. ## References ## * [3]: http://php.net/manual/en/types.comparisons.php -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php