Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:36982 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70985 invoked from network); 12 Apr 2008 06:00:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Apr 2008 06:00:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=truth@proposaltech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=truth@proposaltech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain proposaltech.com from 69.147.64.96 cause and error) X-PHP-List-Original-Sender: truth@proposaltech.com X-Host-Fingerprint: 69.147.64.96 smtp123.sbc.mail.sp1.yahoo.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (2) Received: from [69.147.64.96] ([69.147.64.96:30508] helo=smtp123.sbc.mail.sp1.yahoo.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5C/30-02527-FDF40084 for ; Sat, 12 Apr 2008 02:00:00 -0400 Received: (qmail 43459 invoked from network); 12 Apr 2008 05:59:57 -0000 Received: from unknown (HELO ?192.168.2.101?) (toddruth@sbcglobal.net@69.239.100.91 with login) by smtp123.sbc.mail.sp1.yahoo.com with SMTP; 12 Apr 2008 05:59:56 -0000 X-YMail-OSG: LwINHbYVM1n6j6LysMjZ.K9EhzrnRirZ0CkZKbGc9ofEh5UtEAWH4v7Murs4sg8p23iCUytLK7I7YkzB82Q_9jUL6RLBZigvGIyWV22lqb_2YrRsZzANQ6GRplaN X-Yahoo-Newman-Property: ymail-3 Reply-To: truth@proposaltech.com To: Rasmus Lerdorf Cc: internals@lists.php.net In-Reply-To: <48002CA6.2070003@lerdorf.com> References: <48000275.9090008@daylessday.org> <1207962064.5762.329.camel@inspiron.local> <48002CA6.2070003@lerdorf.com> Content-Type: text/plain Date: Fri, 11 Apr 2008 22:59:49 -0700 Message-ID: <1207979989.5762.340.camel@inspiron.local> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] '1.8' == 1.8 can return false From: truth@proposaltech.com (Todd Ruth) I'd take that as proof of a design flaw in having php doing string to float comparison by casting the string to float instead of the float to a string, but you've got me - the documentation does say the string will be converted to a float and not vice-versa. If it wouldn't be a bad BC break, I think there'd be a lower WTF by doing the cast the other way. "==" means are they the same and "===" means are they the SAME. With "==", '1.8' should match any float that would be displayed as 1.8. (Of course, with "===" they aren't even the same type, so you're false from the start.) I say "should" from an anti-WTF perspective. Again, I must bow to the spec and you have me there. Thanks for saving me the hours of discovering all this via debugging. Please consider the switching of casts for string==float for the suggestion box. - Todd On Fri, 2008-04-11 at 20:29 -0700, Rasmus Lerdorf wrote: > There is no bug here. Please read: > > http://docs.sun.com/source/806-3568/ncg_goldberg.html > > -Rasmus > > Todd Ruth wrote: > > I'm thinking there must be a bug in the heart of php > > causing this. I'll debug it, but I haven't looked at > > php source code in a few years and would like a tip as > > to which files are involved in evaluating "==". Here > > is a fragment from my code and the output: > > > > ... > > print "
\n";
> > var_dump($max);
> > var_dump($nms);
> > var_dump($nms == $max);
> > $max = (float)$max;
> > $nms = (string)$nms;
> > var_dump($max);
> > var_dump($nms);
> > var_dump($nms == $max);
> > $max = (string)$max;
> > $nms = (float)$nms;
> > var_dump($max);
> > var_dump($nms);
> > var_dump($nms == $max);
> > print "
\n"; > > ... > > > > string(3) "1.8" > > float(1.8) > > bool(false) > > float(1.8) > > string(3) "1.8" > > bool(true) > > string(3) "1.8" > > float(1.8) > > bool(true) > > > > I found this using php 5.2.3. I just upgraded to php 5.2.5 > > and am receiving the exact same result. Obviously, I can't > > reproduce it with a simple var_dump("1.8"==1.8). :( > > I guess something is getting corrupted, and I will add debug > > output until I find out what (or Murphy removes the problem > > by adding debug output; then I'm not sure what I'll do). > > > > Thanks for any tips on which files I should look at it. >