Re: Casting Weirdness - Possible PHP BUG?

From: Date: Fri, 02 Apr 2004 22:32:12 +0000
Subject: Re: Casting Weirdness - Possible PHP BUG?
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-26979@lists.php.net to get a copy of this message
D0h! Now I change: $value1 = (string) $value1; To: $value1 = settype($value1, "string"); and it works. Anyone have a clue what is happening here? I know I can use either of the following: $value1 = settype($value1, "string"); $value1 = strval($value1); $value1 = (string) $value1; There seems to be something different with each method, but what...?.. Anyway, I know this should be on a different group, but for some reason I'm having trouble posting anywhere else. "Jeremiah J. Jacks" <jjacks@tamiya.com> wrote in message news:<20040402220703.8840.qmail@pb1.pair.com>... > I don't know why I'm getting weird results here. Maybe someone can > shed some light? (Please see code below) > > On my box I am getting the following output: > Invalid > Valid > > However, it SHOULD be: > Valid > Valid > > ... shouldn't it? > > If I place the 0 in $valid_chars1 anywhere but the beginning or end: > $valid_chars1 = 1234567809; Then it works, but inspection of > $valid_chars1 after it has been cast to > (string) shows "0123456789". > What gives? Why isn't strstr() seeing it? Is this a PHP bug? > > CODE BELOW > ---------------------------------------------------------------------- > ------ > ------------ > function validate($value, $valid_chars) { > for ($i = 0; $i <= strlen($value) - 1; $i++) { > if (!strstr($valid_chars, substr($value, $i, 1))) return false; > } > return true; > } > > $value1 = 123405; > $value1 = (string) $value1; > $valid_chars1 = 0123456789; > $valid_chars1 = (string) $valid_chars1; > $value2 = '123405'; > $valid_chars2 = '0123456789'; > > print validate($value1, $valid_chars1) ? 'Valid' : 'Invalid'; print > "\n"; print validate($value2, $valid_chars2) ? 'Valid' : > 'Invalid';

« previous php.pear.dev (#26979) next »