Re: [RFC] Comparison and conversion inconsistency - need more info

From: Date: Sun, 10 Nov 2013 08:55:53 +0000
Subject: Re: [RFC] Comparison and conversion inconsistency - need more info
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-70071@lists.php.net to get a copy of this message
> min() behavior is nonsense and it would be good fixing min() at some > point. Not many users will be affected, IMO. Seriously, "O" isn't how one should decide to make such a fundamental change to PHP... Anyway, like Stas, I don't really understand the assumptions and conclusions you draw in bug #53104. You claim "Comparison operators evaluate comparison as PHP users expect, but min() does not. This behavior is not intuitive." (Though you didn't cite any expect/intuit statistics.) Your example is: ( -1 > NULL ) // bool(true) ( -1 < NULL) // bool(false) min(-1,NULL)) // NULL Yet these examples are entirely consistent once you accept that the comparison operator must (in PHP) return a boolean, while min() can have a dynamic return type and value. (Contrast this with SQL, in which a comparison may return NULL. If we needed to defensively code in PHP for simple operators to return NULL, we'd then need to make constant use of COALESCE-type wrappers in PHP. This is a dangerous slope.) Not to mention that they are consistent with the docs. To me, inconsistent would be: ( -1 > NULL ) // bool(false) ( -1 < NULL) // bool(true) min(-1,NULL)) // NULL If you had that, you'd have a smoking gun. -- Sandy

« previous php.internals (#70071) next »