List Info

Thread: note 78983 added to language.types.string




note 78983 added to language.types.string
user name
2007-11-05 18:48:19
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...
 */
----
Server IP: 208.69.120.35
Probable Submitter: 131.128.137.187
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php

Edit        -- https://master
.php.net/note/edit/78983
Del: integrated  -- h
ttps://master.php.net/note/delete/78983/integrated
Del: useless     -- http
s://master.php.net/note/delete/78983/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/78983/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/78983/spam
Del: non-english -- 
https://master.php.net/note/delete/78983/non-english
Del: in docs     -- http
s://master.php.net/note/delete/78983/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78983
Reject      -- https://mast
er.php.net/note/reject/78983
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )