Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25331 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76624 invoked by uid 1010); 12 Aug 2006 19:11:02 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 76609 invoked from network); 12 Aug 2006 19:11:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Aug 2006 19:11:01 -0000 X-PHP-List-Original-Sender: ceo@l-i-e.com X-Host-Fingerprint: 67.139.134.202 o2.hostbaby.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (2) Received: from ([67.139.134.202:4203] helo=o2.hostbaby.com) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id CD/90-19138-2C72ED44 for ; Sat, 12 Aug 2006 15:10:59 -0400 Received: (qmail 49059 invoked by uid 98); 12 Aug 2006 19:10:59 -0000 Received: from 127.0.0.1 by o2.hostbaby.com (envelope-from , uid 1013) with qmail-scanner-1.25 ( Clear:RC:1(127.0.0.1):. Processed in 0.079276 secs); 12 Aug 2006 19:10:59 -0000 X-Qmail-Scanner-Mail-From: ceo@l-i-e.com via o2.hostbaby.com X-Qmail-Scanner: 1.25 (Clear:RC:1(127.0.0.1):. Processed in 0.079276 secs) Received: from unknown (HELO l-i-e.com) (127.0.0.1) by localhost with SMTP; 12 Aug 2006 19:10:59 -0000 Received: from 209.254.223.2 (SquirrelMail authenticated user ceo@l-i-e.com) by www.l-i-e.com with HTTP; Sat, 12 Aug 2006 14:10:59 -0500 (CDT) Message-ID: <1133.209.254.223.2.1155409859.squirrel@www.l-i-e.com> In-Reply-To: <002901c6bde3$f3805ea0$0201a8c0@pc1> References: <005101c6b930$83f30b30$0201a8c0@pc1> <00fa01c6bd37$d61d1940$0201a8c0@pc1> <5580.67.108.68.40.1155322579.squirrel@www.l-i-e.com> <002901c6bde3$f3805ea0$0201a8c0@pc1> Date: Sat, 12 Aug 2006 14:10:59 -0500 (CDT) To: "Matt W" Cc: internals@lists.php.net Reply-To: ceo@l-i-e.com User-Agent: Hostbaby Webmail MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Subject: Re: [PHP-DEV] is_numeric_string causes function inconsistency From: ceo@l-i-e.com ("Richard Lynch") [Apologies for having accidentally responded to Matt W off-list, and now bringing it back on-list without asking...] On Sat, August 12, 2006 2:50 am, Matt W wrote: > From: "Richard Lynch" > Sent: Friday, August 11, 2006 > > >> Leading whitespace in PHP means that it's not a number, it's a >> string, >> and it turns into 0. >> >> If you change that, it will break a lot of stuff. >> >> Don't. >> >> :-) > > This is basically what Jochem Mass said, and my reply was: > > "Leading whitespace is already allowed with PHP's is_numeric() > function (and > corresponding internal one), math operations, etc. Only when it > precedes > .123 or -.123 does the behavior change. :-)" > > So with math operations, leading whitespace doesn't cause it (an > otherwise > numeric-prefix string) to turn into 0 (and never has), unless the > first > character(s) after the whitespace are "." or "-." Changing this > specific > (and rarely, if ever, occuring) scenario shouldn't break stuff... but > merely > make it operate the way it should. :-) But I think you are talking about making changes to the way this works: http://example.com/?foo=%20.123 If you break that, you're in big trouble to a lot of scripts all over the planet, which rely on the leading space to trap their SQL problem. I never actually use is_numeric, and would expect it to follow the same "rules" as PHP's internal type-juggling mechanism. I believe leading spaces should NOT be allowed for type-juggling, not is_numeric, because GET/POST/COOKIE data should be subject to the most stringent constraints reasonable to avoid security injections. I really think the community is best served by K.I.S.S. which means is_numeric should follow the same "rules" as type-juggling, so that the programmer is not confused by which does what, and that those rules for what constitutes is_numeric() should not have leading (or trailing) spaces. There is also a paradigm of only specifically allowing what "should be" valid for a validity/security check on data constraints. While I don't think leading/trailing spaces are likely to constitute a Security Issue, there is a Principle at work that I think should be applied. Surely is_numeric(trim($foo)) is the right answer for the programmer who specifically wants to allow spaces. The fact that PHP even allows leading spaces for this is what I would consider a bug: EXPECTED OUTPUT: bar: ACTUAL OUTPUT: bar: 123 I understand the argument that this buggy behaviour is inconsistent with ' .123' and ' -.123' but would counter that the bug is in allowing the leading spaces, and is not best addressed by making it consistently buggy. jmho -- Like Music? http://l-i-e.com/artists.htm