Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21224 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74109 invoked by uid 1010); 15 Dec 2005 06:59:11 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 74094 invoked from network); 15 Dec 2005 06:59:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Dec 2005 06:59:11 -0000 X-Host-Fingerprint: 195.197.172.115 gw01.mail.saunalahti.fi Linux 2.4/2.6 Received: from ([195.197.172.115:42437] helo=gw01.mail.saunalahti.fi) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 82/81-50965-E3411A34 for ; Thu, 15 Dec 2005 01:59:10 -0500 Received: from nest.netphobia.fi (YZDCXXXI.dsl.saunalahti.fi [85.76.35.232]) by gw01.mail.saunalahti.fi (Postfix) with ESMTP id 0B7E41041D2; Thu, 15 Dec 2005 08:59:04 +0200 (EET) Received: from nest.netphobia.fi (nest.netphobia.fi [127.0.0.1]) by nest.netphobia.fi (8.13.1/8.13.1) with ESMTP id jBF6x5Bh006852; Thu, 15 Dec 2005 08:59:05 +0200 Received: from localhost (jani@localhost) by nest.netphobia.fi (8.13.1/8.13.1/Submit) with ESMTP id jBF6x4tl006849; Thu, 15 Dec 2005 08:59:05 +0200 X-Authentication-Warning: nest.netphobia.fi: jani owned process doing -bs Date: Thu, 15 Dec 2005 08:59:04 +0200 (EET) Reply-To: Jani Taskinen To: Greg Beaver cc: php-dev In-Reply-To: <43A0F0BB.6080009@chiaraquartet.net> Message-ID: References: <43A0F0BB.6080009@chiaraquartet.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: Re: [PHP-DEV] why is '01' == '1.'? From: sniper@iki.fi (Jani Taskinen) bool in_array ( mixed needle, array haystack [, bool strict] ) See the last parameter? :) --Jani On Wed, 14 Dec 2005, Greg Beaver wrote: > > Hi all, > > I realize that 1 == '01' and 1 == '1.', but why is this next code also > bool(true)? > > var_dump('1.' == '01'); > ?> > > 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