note 78983 deleted from language.types.string by danbrown

From: Date: Tue, 17 May 2011 14:18:19 +0000
Subject: note 78983 deleted from language.types.string by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179810@lists.php.net to get a copy of this message
Note Submitter: topnotcher at mail dot uri dot edu ---- I have come across this several times, and as far as I can tell, the < and > operators have undocumented functionality when it comes to comparing strings. Consider the following script: <?php $a = '2007-11-05 15:17:49'; $b = '2007-11-05 15:17:48'; $bool = $a > $b; var_dump($bool); //bool(true) /** * The manual tells us that $a and $b should be * truncated at -, thus giving a floating-point value of 2007. * But (2007 > 2007) === false... */ $a = (float)$a; $b = (float)$b; var_dump($a); //float(2007); var_dump($b); //float(2007); /** * And the manual is right. So why does it correctly * compare the dates (which should be treated * as normal strings? Clearly some hidden functionality... */

« previous php.notes (#179810) next »