Re: Implicit isset/isempty check on short-ternary operator
| From: | D. Dante Lorenso | Date: | Sat, 09 Apr 2011 19:20:03 +0000 |
| Subject: | Re: Implicit isset/isempty check on short-ternary operator | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51852@lists.php.net to get a copy of this message | ||
On 4/7/11 5:35 PM, Etienne Kneuss wrote:
On Apr 07 18:03:48, Rasmus Lerdorf wrote:Since I see the beast has risen from the dead, I'd like to chime in again for my proposal to have a "function" called "filled". It is the opposite of empty() and takes variable number of arguments. The first non-empty value is returned. example: $x = filled($myarray['badkey'], $varundef, $obj->nosuch, $default); This *must* be created in the Zend engine because userland can not catch the unset keys and variables. Again, "filled()" would be the opposite of empty() and we'd need some other function similar to be the opposite of isset() if you wanted that type of check. The proposed filled() will suit all my needs with great satisfaction :-) -- Dante ---------- D. Dante Lorenso dante@lorenso.com 972-333-4139On 4/7/11 5:59 PM, Matthew Weier O'Phinney wrote:Well it could (and I believe that was the intention) call !empty instead of isset, that way the semantics would not be changed, appart from the lack of error for undefined variables.It may change the semantics as they stand, but I'd argue that the _expectation_ from the shorthand ternary is to shorten code that currently uses isset(). As it is, I have almost no use for it at this point, as I end up needing to do:Not sure why you would have that expectation. The long ternary doesn't do that, and there is nothing about the short ternary that changes that. There was talk of a new ifsetor type of operator to have those semantics but never any talk of changing existing semantics.$value = isset($a[$key]) ? $a[$key] : 'Not set';which is exactly the situation I had before it was introduced.