php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34896 Error in control structures between integer and string
Submitted: 2005-10-17 20:31 UTC Modified: 2005-10-17 20:35 UTC
From: decryptus at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.4.0 OS: Linux debian
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: decryptus at gmail dot com
New email:
PHP Version: OS:

 

 [2005-10-17 20:31 UTC] decryptus at gmail dot com
Description:
------------
I have a problem when I compare two variables, one is an integer the other is a string.

So when I do a "if" between these variables, the result is true.

I use '==' to compare these variables, I can use '===', but in the logic two differents values should'nt be true.

Reproduce code:
---------------
-------------------
$foo_1 = 2005; # an integer
$foo_2 = '2005-10'; # a string

if($foo_1 == $foo_2)
	print 'result true : '.$foo_1;
else
	print 'result false : '.$foo_2;
-------------------


Expected result:
----------------
# foo_2's value :
result false : 2005-10

Actual result:
--------------
# foo_1's value :
result true : 2005

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-17 20:35 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Use "===" operator for that.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 15:00:01 2025 UTC