ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 I've run into a rather odd problem that I've run out of ways of diagnosing (mostly because there doesn't seem to be any possible explanation). The simplest way I can describe it is simply by showing the code and displaying the output: <?php $count_all = 0; if ($permission->check_permission($proper_parameters)) $count_all += 2; if ($permission->check_permission($proper_parameters)) $count_all += 4; if ($permission->check_permission($proper_parameters)) $count_all += 2; if ($permission->check_permission($proper_parameters)) $count_all += 1; if ($permission->check_permission($proper_parameters)) $count_all += 1; if ($permission->check_permission($proper_parameters)) $count_all += 1; if ($permission->check_permission($proper_parameters)) $count_all += 1; if ($permission->check_permission($proper_parameters)) $count_all += 1; echo ' >= '.$count_all; // echoes: >= 10 echo ' >= '.$count_all; // echoes: >= 101 ?> I'm not sure if this will help diagnose, but: <?php $count_all = 0; if ($permission->check_permission($proper_parameters)) $count_all += 2; if ($permission->check_permission($proper_parameters)) $count_all += 4; if ($permission->check_permission($proper_parameters)) $count_all += 2; if ($permission->check_permission($proper_parameters)) $count_all += 1; if ($permission->check_permission($proper_parameters)) $count_all += 1; if ($permission->check_permission($proper_parameters)) $count_all += 1; if ($permission->check_permission($proper_parameters)) $count_all += 1; if ($permission->check_permission($proper_parameters)) $count_all += 1; echo ' >= '.$count_all; // echoes: >= 10 echo ' >= '.$count_all; // echoes: >= 10 echo ' >= '.$count_all; // echoes: >= 101 ?> $count_all should be 10, I have no idea why it suddenly changes to 101. The problem is that following these echoes is an "if" evaluation of a count on an array and the $count_all variable. Because $count_all seems to spontaneously change, the evaluation always results in false. I first discovered the bug when I attempted to submit a form via AJAX. Instead of informing me that there were no updates to be made, the AJAX request received no response. This is the only appearance of $count_all in any of my files, this is the only time I've ever used a variable with this name in this project. It doesn't appear before this in the file, nor does it appear again after (except in the "if" evaluation following the echoes). If more code needs to be posted I will do so. There's no loop involved here, the above code appears within an "if" statement that appears within a switch's case. I don't see how any previous code could cause this problem, as I've said, $count_all is never used before or after the above code anywhere. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 25, 2009 Share Posted April 25, 2009 You're echoing something else out in the code somewhere after that last $count_all that is equal to 1. Since there's no newline or anything, it appears right next to it. <?php $count_all = 10; echo "$count_all $count_all $count_all"; //arbitrary code here, as long as it doesn't echo anything echo true; ?> Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Author Share Posted April 25, 2009 DarkWater, thanks for the duh moment! I knew it was going to be something intuitively obvious but just couldn't figure it out. It appears there's something wrong with my AJAX in processing the response. 1 is what it should have been getting all along, but after a recent update it seems to not process it correctly anymore. In any event, thanks again. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 25, 2009 Share Posted April 25, 2009 No problem. =P Quote Link to comment 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.