Jump to content

Recommended Posts

Goodday all,

Perhaps you can help shed some light on this:

[code]
        $query = "select count(clientid) as c from xxx where clientid='".$this->session->getclientid()."'";
        $cnt = $this->db->selectSQL($query);
$valid = $valid and $cnt['c']<=GSInfo::$maxGS;
[/code]

Now, the value of $cnt at this point is 22, and the value of GSInfo::$maxGS is 15.  For whatever reason, php is setting $valid to true, when clearly 22<=15 is false.  I thought perhaps that the sql query might be spitting out a string, but this would not be an issue in PHP correct?  Perhaps its a lack of understanding on my part on the behaviour of PHP vs C++/Java/Ada. 

Thanks for the help,
Rob
Link to comment
https://forums.phpfreaks.com/topic/34769-issue-with-operator-and-integer-values/
Share on other sites

i havent checked this out, but depends on the order of operators - ie, which gets dealt with first when calculating:

[code]
$valid = $valid and $cnt['c']<=GSInfo::$maxGS;
[/code]

it seems that, given the numbers you state, the above is being evaluated as ($valid and $cnt['c']) <= GSInfo::$maxGS; . try throwing in some brackets to specifically state your order:

[code]
$valid = $valid && ($cnt['c'] <= GSInfo::$maxGS);
[/code]
cool!

even still.i actually find it always pays anyway to use brackets - both from a debugging point of view, but also a portability one. There's countless occasions I can think of where I've been required to go through code written using one language putting brackets in for another language, due to the calculation order being different.

anyway - glad it helped!
cheers
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.