note 44086 added to types.comparisons

From: Date: Wed, 14 Jul 2004 23:12:25 +0000
Subject: note 44086 added to types.comparisons
Groups: php.notes 
Request: Send a blank email to php-notes+get-73247@lists.php.net to get a copy of this message
> This means that PHPs implicit typecasting > is *NOT TRANSITIVE* as one might expect > it to be, since "php" == 0, but "php" == true > and 0 == false. Yes, this seems to be non transitive. If you expect transitivity you would expect "php"==0 and false==0 => "php" == false this doesn't happen in PHP. in PHP, "php"==0 and false==0 -but- "php" != false But - it is not legitimate to expect transitivity because you are dealing with different types - you compare strings, booleans and integers. You may expect transitivity when comparing strings to strings, booleans to booleans and ints to ints (this seems to be transitive even in PHP :), but whenever you try to compare strings to ints and booleans to strings you must rely on the translation table PHP provides - which is perfectly logical from a programmers point of view, even if it doesnt provide for that transitivity between a string, a zero integer and a false boolean. This is similar to the problem they teach you in earlier math classes: 5 apples and 4 apples equals to 9 apples, but you can't add 5 apples and 4 bananas. ---- Manual Page -- http://www.php.net/manual/en/types.comparisons.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44086 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44086&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44086&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73247) next »