#23088 [Bgs]: 'if' 'else' has a strange behavior.
| From: | batera at linux dot ime dot usp dot br | Date: | Tue, 08 Apr 2003 12:10:36 +0000 |
| Subject: | #23088 [Bgs]: 'if' 'else' has a strange behavior. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-37346@lists.php.net to get a copy of this message | ||
ID: 23088
User updated by: batera at linux dot ime dot usp dot br
Reported By: batera at linux dot ime dot usp dot br
Status: Bogus
Bug Type: *General Issues
Operating System: Slackware Linux
PHP Version: 4.3.2RC1
New Comment:
Hello.
The same problem happened in php 4.3.1. Anyway, let me explain you
better why I think it may be a bug.
First, why should it be '!==' instead of '!='?! I'm not comparing
types, only the value!
I have this 'if' that should be "false" (i tested the values) and
always returns "true"
To check if it was a sintax error (before my 1st post), i tryed
this:
<?
$x = 0;
if (!isset($usuario))
$x = 1;
if ($usuario != $login)
$x = 1;
if ($usuario == 'logoff')
$x = 1;
if ($user_senha != $senha)
$x = 1;
if ($user_senha == 'null')
$x = 1;
echo $x;
?>
At this point I've got what I expected.
My next step was to remove the "echo $x" and put $x into an if.
<?
if ($x) {
echo "It's true! \$x == $x";
}
?>
And guest what?! The value of $x become 1!!!!
So I changed the if to:
if ($x == 1)
And $x became 1 again.
So, I tried:
if ($x == 0)
And $x became 0!!!
As you can see, I used "==", not "="! And, again, I don't whant to
check the types!
I've put back the "echo $x" before "if ($x)", and now it worked fine!
No errors at all!
I tried to use some else case, and wrote it:
<?
if ($x) {
echo "It's true! \$x value is $x";
}
else {
echo "It's false! \$x is $x!";
}
?>
Now, gess what was the output?!
"It's false! $x is 0!";
Can you belive it?! Maybe it's a hardware failure or something, but it
just happened in this unique file!
index.php
And also, it uses session.
I didn't wrote the entire code and it was working in a win98 machine.
I've put it in a server with php 4.2.3 and worked.
I haven't tested it in my machine with this version of PHP.
I gess it's all now.
Sorry about my 1st post.
best wishes.
Previous Comments:
------------------------------------------------------------------------
[2003-04-07 18:03:55] sniper@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php
If you can provide more information, feel free to add it
to this bug and change the status back to "Open".
Thank you for your interest in PHP.
..and doesn't really look like any bug, just misunderstanding about
how things work..
------------------------------------------------------------------------
[2003-04-07 12:03:09] jlg at huelladigital dot net
You have a syntax error in your script.
It says:
if (!isset($usuario) OR $usuario != $login (...)
^^
It should say:
if (!isset($usuario) OR $usuario !== $login (...)
^^^
------------------------------------------------------------------------
[2003-04-07 08:06:36] batera at linux dot ime dot usp dot br
The best whay to show you my problem is send you my example.
This expression works as expected:
<?
if (!isset($usuario) OR $usuario != $login OR $usuario == 'logoff' OR
$user_senha != $senha OR $user_senha == 'null') {
echo "okokok";
}
else
echo "corrigido!";
?>
but, when I remove the 'else', 'if', tha in first was false, become
true.
<?
if (!isset($usuario) OR $usuario != $login OR $usuario == 'logoff' OR
$user_senha != $senha OR $user_senha == 'null') {
echo "ppp";
}
?>
I'll go back to php 3.1 'cause I need it working.
Please, let me know when this bug is fixed.
tx a lot.
you allways have done a grate job!
best wishes
OgRo
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23088&edit=1