Re: why is '01' == '1.'?

From: Date: Thu, 15 Dec 2005 12:47:54 +0000
Subject: Re: why is '01' == '1.'?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-21229@lists.php.net to get a copy of this message
On 12/14/05, Greg Beaver <greg@chiaraquartet.net> wrote: > 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.'))) Perhaps if (preg_match('/^[10]\./',$ltrimword)) would be both more concise and express your intent better? Regards, Jason http://blog.casey-sweat.us/

« previous php.internals (#21229) next »