Casting Weirdness - Possible PHP BUG?
| From: | Jeremiah J. Jacks | Date: | Fri, 02 Apr 2004 22:07:05 +0000 |
| Subject: | Casting Weirdness - Possible PHP BUG? | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-26977@lists.php.net to get a copy of this message | ||
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';