Re: Implicit isset/isempty check on short-ternary operator

From: Date: Fri, 08 Apr 2011 16:05:42 +0000
Subject: Re: Implicit isset/isempty check on short-ternary operator
References: 1 2 3 4 5 6 7 8 9 10 11 12 13  Groups: php.internals 
Request: Send a blank email to internals+get-51844@lists.php.net to get a copy of this message
On 9/04/11 12:45 AM, Martin Scotta wrote:
I just feels that !empty($arr['key']) or isset($arr['key']) do not express the real meaning, instead I would choose to write array_key_exists('key', $arr). It may be slower but it clearly express what I meant.
I don't like this. array_key_exists will return true for an array key that exists but is set to null, which is rarely what is wanted (though it sometimes is). I agree that the variants with empty() aren't very good. Just a single isset() variant seems like a good idea. I favour the ??: syntax. I liked the well-thought-out examples with assignment and chaining and so on. For chaining, does associativity matter? (Too tired to figure it out for myself right now!) Ben.

« previous php.internals (#51844) next »