PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

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
View/Vote Developer Edit Submission

Welcome! If you don't have a SVN account, you can't do anything here. You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
SVN Username: SVN Password:
Quick Fix:
Status: Assign to:
Category:
Summary:
From: adrian at ciutureanu dot ro
New email:
Version: OS:
New/Additional Comment:

[19 Dec 2001 11:11am UTC] adrian at ciutureanu dot ro
<?php
	$i = 0;
	$s = 'the string';
	if($i == $s) {
		echo "'$s' == $i";
	} else {
		echo "'$s' != $i";
	}
?>
// This outputs 'the string' == 0
[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

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC