php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23088 'if' 'else' has a strange behavior.
Submitted: 2003-04-07 08:06 UTC Modified: 2003-04-09 07:15 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: batera at linux dot ime dot usp dot br Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.2RC1 and 4.3.1 OS: Slackware Linux
Private report: No CVE-ID: None
 [2003-04-07 08:06 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-07 12:03 UTC] 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 18:03 UTC] 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-09 06:10 UTC] batera at linux dot ime dot usp dot br
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.
Sorry cause I posted 2 times this one.

best wishes.
 [2003-04-09 06:31 UTC] sniper@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. 

Thank you for your interest in PHP.

.
 [2003-04-09 07:15 UTC] batera at linux dot ime dot usp dot br
I fixed the erros with session - my buddy mad a lot of mistakes - and It started working.
The problem isn't with the 'if' and 'else' case, but with error handling in session.

well, anyway, tx about your patience.

OgRo
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC