• Welcome to Valhalla Legends Archive.
 

[PHP] True = False

Started by idiat, May 08, 2007, 06:25 PM

Previous topic - Next topic

idiat

OK, so I've got this function, right. It goes a little something like this:


function ConnectBNCS($quiet) {
ap(BNCS, yellow, "Inside Connect");
global $BNCS, $config;
if (!$quiet)
ap(BNCS, yellow, "Connecting...");
ap(BNCS, yellow, $config["server"]);
$BNCS = new PacketBuffer;
if (!$BNCS->Connect($config["server"], 6112)) {
ap(BNCS, red, "Connection failed.");
exit;
}
ap(BNCS, yellow, "Inside Connect3");
if (!$quiet)
ap(BNCS, green, "Connected!");
ap(BNCS, yellow, "Inside Connect4");
}


And when I call it like so:
ConnectBNCS(false);

All it does is output:

[6:15:38 PM] [BNCS] Inside Connect
[6:15:39 PM] [BNCS] useast.battle.net
[6:15:39 PM] [BNCS] Inside Connect3
[6:15:39 PM] [BNCS] Inside Connect4

Why?
-idiat. Spell it right. No caps either.
-Mary Naivete, sound advice from a sound woman.

rabbit

Because ! is a binary operator.  Use == false or != true.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

idiat

#2
That didn't change anything either, though that is interesting to know.

I've tried:
-Using $quiet == false instead
-Using $quiet == true ($quiet is true incidentally, even though I set it to false)
-Setting $quiet to 0 instead of false
-Setting $quiet to an arbitrary number (52), it still appeared as 1 throughout the function
-Reorganizing the if statement in many different ways
-Using a different name for $quiet
-Restarting Apache
-Restarting computer
-Resetting PHP configuration

It worked before and I didn't make any changes to the code to break it.

Also, it's NOT connecting to the specified server, (figured out while trying to connect to localhost instead), even though it has before, to the point where I've been able to log in and chat.
-idiat. Spell it right. No caps either.
-Mary Naivete, sound advice from a sound woman.

warz

im going to go out on a limb here, but im willing to bet that something is wrong, or is not working how you intend it to be working.

idiat

omg how'd you know?!

I intend for $quiet to be set according to what I set it to but PHP is setting it to 1 on its own accord.
-idiat. Spell it right. No caps either.
-Mary Naivete, sound advice from a sound woman.

Banana fanna fo fanna

Could this be related to register_globals?

iago

Quote from: idiat on May 09, 2007, 07:30 AM
omg how'd you know?!

I intend for $quiet to be set according to what I set it to but PHP is setting it to 1 on its own accord.

He has a point, even if he said it in a round-about way.

The code that I can see is correct. There is absolutely nothing wrong with the code you posted there. Here's a test I did to confirm that:
ron@facevision:~$ cat test.php
<?php

        function test($quiet)
        {
                if(!$quiet)
                        print "Noisy!!\n";
        }


        print "True: ";
        test(true);

        print "\nFalse: ";
        test(false);

        print "\n";

?>

ron@facevision:~$ php test.php
True:
False: Noisy!!


Obviously, something else is pooched. Check the value of $quiet within that function. Check for multiple functions with the same name, old versions of files, and misspellings.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


idiat

I tested the exact same code on Ubuntu and it works correctly. :-/
-idiat. Spell it right. No caps either.
-Mary Naivete, sound advice from a sound woman.

iago

In that case, perhaps you're using a weird/broken version of PHP. Try using the "===" operator, "if($quiet === false)". I doubt it'll make a difference, but it's worth a try.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


MyndFyre

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

rabbit

Bleh...wrong word.  I've never had all them formal teachins like youse did.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.