php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10234 if (... != ...) does not work properly with strings
Submitted: 2001-04-08 14:58 UTC Modified: 2001-04-08 15:08 UTC
From: ruslan2000 at mail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.0.4pl1 OS: Win2000 Prof
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git 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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ruslan2000 at mail dot com
New email:
PHP Version: OS:

 

 [2001-04-08 14:58 UTC] ruslan2000 at mail dot com
<?php
/*
I want to compare two strings and if they are equal show a message on the screen.
But I discovered that it's imposible, because PHP think that they are equal anyway :(((

Example of script
*/

//EX 1. something wrong
$qqq = "00041001001001001001001001001001001002000";
$xxx = "00041001001001001000000000000000000000000";

# with != just the same effect as <>
if ($qqq <> $xxx)
	 echo "<hr>$qqq<br> <b>!=</b> <br>$xxx<hr>"; //it should be on the screen, but ... 
else 
	echo "<hr>$qqq<br> <b>=</b> <br>$xxx <hr>"; //it's appear every time on the screen :(((

if ($qqq != $xxx) 
	echo "<hr>$qqq<br> <b>!=</b> <br>$xxx";
else 	
	echo "<hr>$qqq<br> <b>=</b> <br>$xxx <hr>";

//(strval($qqq) != strval($xxx)) does not work too 
if (strval($qqq) != strval($xxx))
	 echo "<hr>$qqq<br> <b>!=</b> <br>$xxx<hr>";
else
	 echo "<hr>$qqq<br> <b>=</b> <br>$xxx <hr>";

//EX 2  - all OK

$qqq = "00041001000000000000000000000000000000000";
$xxx = "00041001001001001001001001001001001002000";

# with != just the same effect as <>
if ($qqq <> $xxx)
	echo "$qqq<br> <b>!=</b> <br>$xxx";
else 
	echo "$qqq<br> <b>=</b> <br>$xxx <hr>";

if ($qqq != $xxx)
	echo "$qqq<br> <b>!=</b> <br>$xxx";
else 
	echo "$qqq<br> <b>=</b> <br>$xxx <hr>";

?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-08 15:08 UTC] cnewbill@php.net
For string comparison use !== for NOT and === for EQUALS.

-Chris
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri May 24 14:01:26 2019 UTC