Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21223 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43689 invoked by uid 1010); 15 Dec 2005 04:27:49 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 43674 invoked from network); 15 Dec 2005 04:27:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Dec 2005 04:27:49 -0000 X-Host-Fingerprint: 69.64.38.41 bluga.net Linux 2.5 (sometimes 2.4) (4) Received: from ([69.64.38.41:58808] helo=bluga.net) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 23/CB-18503-4C0F0A34 for ; Wed, 14 Dec 2005 23:27:48 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by bluga.net (Postfix) with ESMTP id 54CBF21CD62 for ; Wed, 14 Dec 2005 22:29:38 -0600 (CST) Received: from bluga.net ([127.0.0.1]) by localhost (bluga.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 29054-18 for ; Wed, 14 Dec 2005 22:29:38 -0600 (CST) Received: from [192.168.1.44] (pool-71-247-25-164.nycmny.east.verizon.net [71.247.25.164]) by bluga.net (Postfix) with ESMTP id 1143121CD60 for ; Wed, 14 Dec 2005 22:29:38 -0600 (CST) Message-ID: <43A0F0BB.6080009@chiaraquartet.net> Date: Wed, 14 Dec 2005 23:27:39 -0500 User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: php-dev X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new using ClamAV at bluga.net Subject: why is '01' == '1.'? From: greg@chiaraquartet.net (Greg Beaver) Hi all, I realize that 1 == '01' and 1 == '1.', but why is this next code also bool(true)? In this case, a string is explicitly being compared to a string, and yet both are being converted to an int prior to comparison. I can understand that implicit type conversion is needed when comparing strings to ints, but this can be dangerous. phpDocumentor, for instance uses this code: if (in_array(substr($ltrimword, 0, 2), array('1.', '0.'))) and assumes that it will only match either '1.' or '0.', but in fact, it will match '01', '1.', '0.', '00', and as such if this happens to be encountered, it can cause an infinite loop in phpDocumentor eating up all memory (bad - will be fixed in next release). Of course, I can fix this by using === for each element instead of in_array(), but this is extremely non-intuitive and dangerous behavior in the underlying PHP implementation. The manual says nothing about auto-conversion of strings to ints when comparing two strings that satisfy is_numeric(). My question is whether this is a documentation or an internal PHP error? Greg