php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39264 Problem with IF sentence
Submitted: 2006-10-26 11:46 UTC Modified: 2006-10-26 11:52 UTC
From: hipolitoalvarez at yahoo dot com dot ar Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 4.4.4 OS: Windows/Apache2
Private report: No CVE-ID: None
 [2006-10-26 11:46 UTC] hipolitoalvarez at yahoo dot com dot ar
Description:
------------
The problem begins when i compare an expression in IF sentence.
When i compare a STRING with another STRING(component of array).

For example: if ($b != $a[$x]) this always gives me a TRUE even if $b=3 and $a[$x]=3.

For example: if ($b == $a[$x]) this always gives me a FALSE even if $b=3 and $a[$x]=3.

Reproduce code:
---------------
example: $indice(ARRAY) = 1 | 2 | 3 | 4 | 5 |
example: $id = 3
<?
$cant = count($indice);
$id = $_POST[cual];
$x = 0;
while ($x < $cant){
if ($id <> $indice[$x]) {
...several sentences...
}
$x++;
}
?>



Expected result:
----------------
Ill expect when the "if" sentence compare the expression, if the values are equals, expression begin FALSE, if are not equals, expression begin TRUE, but are always TRUE even when bot variables have the same value.
If i change the disctinct comparation sign (<> or !=) to an equal sign (== or ===) always give me the result of FALSE, so dont enter into IF sentence.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-26 11:52 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

This works fine:

derick@kossu:~$ php -r \'$a = array( 3 ); $b = 3; $x = 0; var_dump( $b != $a[$x] );\'

bool(false)

derick@kossu:~$ php -r \'$a = array( 3 ); $b = 3; $x = 0; var_dump( $b == $a[$x] );\'

bool(true)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC