LDMartin1959 Posted December 5, 2013 Share Posted December 5, 2013 (edited) I have the following code: <?php if(($time_now<$str) && (($post->register=="0") || ($close_reg<$time_now))) { echo $online_reg_closed_message; } else if(($str<$time_now) && (($row->register=="0") || ($auto_close_reg<$time_now))) { echo $reg_closed_message; } else { echo $final_message; } ?> I checked the values of the variables and they come back as this (shortened to significant values only for clarity: $auto_close_reg 84340 $time_now 70164 (at the time of testing, at any rate) $str 66400 $close_reg 16000 $post->register 0 Now, if the logic is functioning correctly I should (at the time of testing) be seeing the message stored in$reg_closed_message displayed. I'm not. I'm seeing $final_message. It's probably something obvious but I can't see it. What did I do wrong here? Thank you. Edited December 5, 2013 by LDMartin1959 Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/ Share on other sites More sharing options...
KevinM1 Posted December 5, 2013 Share Posted December 5, 2013 $time_now IS NOT less than $str. Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461398 Share on other sites More sharing options...
LDMartin1959 Posted December 5, 2013 Author Share Posted December 5, 2013 (edited) $time_now IS NOT less than $str. Correct, which means the second if statement should be true (at least, if I did my logic correctly): IF $str is less than $time_now [true] AND (($row->register=="0") [it is not] OR ($auto_close_reg is less than $time_now) [it is, thus making the OR clause true]) then echo $reg_closed_message Edited December 5, 2013 by LDMartin1959 Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461400 Share on other sites More sharing options...
KevinM1 Posted December 5, 2013 Share Posted December 5, 2013 (edited) Odd. I created the following test script: $time_now = 70000; $str = 66000; $close_reg = 16000; class testPost { public $register; } class testRow { public $register; } $post = new testPost; $post->register = "blah"; $row = new testRow; $row->register = "0"; if(($time_now < $str) && (($post->register == "0") || ($close_reg < $time_now))) { echo "online_reg_closed_message"; } else if(($str < $time_now) && (($row->register == "0") || ($auto_close_reg < $time_now))) { echo "reg_closed_message"; } else { echo "final_message"; } And it echoes "reg_closed_message" for me. My only conclusion is that your values aren't what you think they are at the moment of the conditonals. EDIT: Assigning a non-zero string to $row->register results in the same - "reg_closed_message" being echoed. Edited December 5, 2013 by KevinM1 Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461403 Share on other sites More sharing options...
LDMartin1959 Posted December 5, 2013 Author Share Posted December 5, 2013 Odd. I created the following test script: $time_now = 70000; $str = 66000; $close_reg = 16000; class testPost { public $register; } class testRow { public $register; } $post = new testPost; $post->register = "blah"; $row = new testRow; $row->register = "0"; if(($time_now < $str) && (($post->register == "0") || ($close_reg < $time_now))) { echo "online_reg_closed_message"; } else if(($str < $time_now) && (($row->register == "0") || ($auto_close_reg < $time_now))) { echo "reg_closed_message"; } else { echo "final_message"; } And it echoes "reg_closed_message" for me. My only conclusion is that your values aren't what you think they are at the moment of the conditonals. I echoed the values to the screen and those are the values it gave back (edited, as I said). The echo code is: echo "Start Time: " . $str . "<br />"; echo "Online Reg Close: " . $close_reg . "<br />"; echo "AutoClose: " . $auto_close_reg . "<br />"; echo "Current Time: " . $time_now . "<br />"; echo "Post register: " . ($post->register) . "<br />"; The returned values are (as of the time of testing): Start Time: 1386266400 Online Reg Close: 1386201600 AutoClose: 1386277140 Current Time: 1386270164 Post register: 0 Unless my eyes are deceiving me (and I'll grant that's a possibility), these values still fulfill the second if statement as true. Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461406 Share on other sites More sharing options...
kicken Posted December 5, 2013 Share Posted December 5, 2013 Your second condition is using $row->register, not $post->register. Not sure if that is intentional or not, but guessing not since you never mention $row->register anywhere else. Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461435 Share on other sites More sharing options...
Solution LDMartin1959 Posted December 6, 2013 Author Solution Share Posted December 6, 2013 Your second condition is using $row->register, not $post->register. Not sure if that is intentional or not, but guessing not since you never mention $row->register anywhere else. No, wasn't intentional (although in terms of the logic result, it shouldn't make any difference as far as I can tell since the full statement still returns true). I am working on adding this logic to several WordPress templates on this site and apparently different people coded not only different pages but different portions of the pages and there are a LOT of inconsistencies in how things are done from page to page, and section to section. So that was my error for not getting all the changes made in that location. But I'm still not seeing any change in behaviour even with the correction. Frankly, there are tons of issues with this site: on a totally unrelated issue, the site has two different contact form which submit information via the mail() function, but one of them doesn't work despite the fact that PHP returns true from the function (which should mean that PHP successfully submitted the data) on both, the fact that both are in the same directory and both files are set to the same Unix permissions levels, since the one works it shouldn't be a PHP.ini setting and the one that failed simply stopped working one day even though no one touched the file or (as far as I can tell) any of the supporting files. Ugggh. This is probably not the best site for someone with my lack of PHP experience to be "gaining experience" with. Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461490 Share on other sites More sharing options...
KevinM1 Posted December 6, 2013 Share Posted December 6, 2013 It also doesn't help that you're using WordPress, which is a terrible brew of bad coding practices and hacks under the hood. Its ubiquity is in direct opposition with its quality. Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461497 Share on other sites More sharing options...
kicken Posted December 6, 2013 Share Posted December 6, 2013 It's better to use var_dump to check what the values of your variables are, incase there is any implicit conversion going on when echoing that is making them appear to match when they don't. It'll also help you detect things like extra spaces/characters at the start/end of a string. Before your if add var_dump($str , $time_now , $row->register , $auto_close_reg);so you can see the true values of each of the variables in your condition. Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461504 Share on other sites More sharing options...
LDMartin1959 Posted December 6, 2013 Author Share Posted December 6, 2013 It's better to use var_dump to check what the values of your variables are, incase there is any implicit conversion going on when echoing that is making them appear to match when they don't. It'll also help you detect things like extra spaces/characters at the start/end of a string. Before your if add var_dump($str , $time_now , $row->register , $auto_close_reg);so you can see the true values of each of the variables in your condition. Thanks for the tip. Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461508 Share on other sites More sharing options...
LDMartin1959 Posted December 6, 2013 Author Share Posted December 6, 2013 It also doesn't help that you're using WordPress, which is a terrible brew of bad coding practices and hacks under the hood. Its ubiquity is in direct opposition with its quality. Well, I just got thrown into this after the mess was made. I had nothing to do with creating it!! Quote Link to comment https://forums.phpfreaks.com/topic/284562-logic-fails/#findComment-1461509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.