| Bug #14605 | compare string with integer 0 returns t | ||||
|---|---|---|---|---|---|
| Submitted: | 19 Dec 2001 11:11am UTC | Modified: | 19 Dec 2001 11:24am UTC | ||
| From: | adrian at ciutureanu dot ro | Assigned to: | |||
| Status: | Bogus | Category: | Scripting Engine problem | ||
| Version: | 4.1.0 | OS: | Windows NT 4 sp 6a | ||
[19 Dec 2001 11:21am UTC] jan@php.net
this i due to the autoconversation of variables in PHP. Your string is converted into an integer during the comparison.The integer is 0, since no fitting value can be found. So 0 equals 0.
[19 Dec 2001 11:24am UTC] derick@php.net
Use === instead of == Derick

<?php $i = 0; $s = 'the string'; if($i == $s) { echo "'$s' == $i"; } else { echo "'$s' != $i"; } ?> // This outputs 'the string' == 0