Jakub Vrana wrote:
Sara Golemon wrote:
with thanks to Sara! - because (not for the first time) your post
allowed me to learn/understand some new stuff. (Sara seems to
have a knack for explaining stuff in a way that dummies can [also]
understand it - that a good thing[tm]!)
Yes, and that's the problem. $a > $b *isn't* read by the current parser as
$a > $b, it's read as $b < $a.
For all normal PHP comparisons, the distinction is unimportant... 4 < 2
and 2 > 4 will both evaluate to false after all.
Array comparison is due this logic also strange:
$a = array(0, 1);
$b = array(1 => 0, 0 => 1);
I started playing with this because I didn't understand it.
I could only make both the LT and the GT expressions equal true
with these particular arrays. for instance if I changed them
to:
$a = array(0, 1);
$b = array(0 => 1, 1 => 0);
then the var_dump() statements give me:
bool(true)
bool(false)
Personally I would never use a statement like ($a < $b)
if $a and $b are arrays - mainly because I have no idea what that
really means (array $a being 'less than' $b) so the determining
whether $a is 'less than' $b is not much use. given that fact I'm not
fussed whether array comparison (in such a way) is broken or not ...
but I am very interested to here 'core people's advice on using this
kind of expression syntax with arrays (I feel objects have the same
problem as arrays with regard to what 'greater than'/'less than' really
means when comparing to object variables).
var_dump($a < $b); // true
var_dump($a > $b); // true
$a is both less than and greater than $b.
Jakub Vrana
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php