Re: [off] PHP: a fractal of bad design

From: Date: Mon, 07 May 2012 18:07:49 +0000
Subject: Re: [off] PHP: a fractal of bad design
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-60511@lists.php.net to get a copy of this message
> On 05/07/2012 05:32 AM, Tjerk Anne Meesters wrote: > >> Validated or not, why would type juggling even come into the picture >> if both variables are of the same type? > > For the simple reason that web forms return all input as strings, even > if the input is actually meant to be numeric > > Many PHP database backend functions also return all result fields > as strings regardless of the actual result type, e.g. mysql_fetch_*(), > mysqli_fetch_*() and pg_fetch_*()  (although that's more debatable) Granted, I realized that my comment came across a bit too generic. What I meant to say is that the type juggling should be applied within its realm of usefulness and skipped otherwise lest it tell me "they're both pretty big numbers" :) I've always felt overly pedantic when I used === or strcmp() in string comparisons (assuming the equality edge cases were not an issue; e.g. same string composition). > > So if both operands look numeric (even though they are actually of > type string) type juggling kicks, and in your MD5 example it > unfortunately kicks in with a conversion to float for both sides > and you're running into the "never compare floats for equality" > trap ... (which is being worked on for the string comparison case > though, i just don't have the bug number at hand right now) I'm assuming that you're referring to this bug reference: https://bugs.php.net/bug.php?id=54547 The proposed patch therein looks okay, though I'm not sure why the added test case is for 64bit systems only; seems to me that it can / should be run for other systems too.

« previous php.internals (#60511) next »