Re: Implicit isset/isempty check on short-ternary operator
| From: | Rasmus Lerdorf | Date: | Fri, 08 Apr 2011 05:01:42 +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-51833@lists.php.net to get a copy of this message | ||
On 04/07/2011 07:02 PM, Stas Malyshev wrote:
Hi!I'm not against coming up with a cleaner no-warning mechanism for this. I was just responding to the idea that the intent of ?: was to solve this. It never was. We need to be careful about changing the beahviour of existing operators. -RasmusIt is true, however I think the amount of boilerplate code produces by this paradigm is staggering, and it's about time we fixed that. We had a chance of doing it with ?: but for one reason or another it was passed, but the need is still there. I think actually the idea of "expr ?? expr2", meaning (isset($expr)?$expr:$expr2) is not bad. Anybody sees any holes in it? And yes, I wouldn't be disappointed too much if ?: didn't generate notices either. With modern IDEs times when it helped catch typos are mostly gone, and now these warnings are just a very annoying reason to write boilerplate code.$value = isset($a[$key]) ? $a[$key] : 'Not set'; which is exactly the situation I had before it was introduced.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.