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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
12 - 8 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 04:01:29 2024 UTC