php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14605 compare string with integer 0 returns t
Submitted: 2001-12-19 11:11 UTC Modified: 2001-12-19 11:24 UTC
From: adrian at ciutureanu dot ro Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.1.0 OS: Windows NT 4 sp 6a
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: adrian at ciutureanu dot ro
New email:
PHP Version: OS:

 

 [2001-12-19 11:11 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-19 11:21 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.
 [2001-12-19 11:24 UTC] derick@php.net
Use === instead of ==

Derick
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 06:01:29 2025 UTC