Valhalla Legends Forums Archive | Web Development | [PHP] True = False

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


Code:
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:
Code:
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?
May 08, 2007, 06:25 PM
rabbitBecause ! is a binary operator.  Use == false or != true.May 08, 2007, 07:46 PM
idiatThat 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.
May 08, 2007, 08:03 PM
betawarzim 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.May 09, 2007, 03:11 AM
idiatomg 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.
May 09, 2007, 07:30 AM
Banana fanna fo fannaCould this be related to register_globals?May 09, 2007, 11:40 AM
iago
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.
May 09, 2007, 01:12 PM
idiatI tested the exact same code on Ubuntu and it works correctly. :-/May 09, 2007, 04:08 PM
iagoIn 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. May 09, 2007, 05:20 PM
MyndFyre[vL]
Because ! is a binary operator.  Use == false or != true.

! is not a binary operator.  It's a unary operator.
May 17, 2007, 11:16 AM
rabbitBleh...wrong word.  I've never had all them formal teachins like youse did.May 17, 2007, 12:10 PM