James-A Posted November 8, 2013 Share Posted November 8, 2013 $_DB['DIR']="Directory_database"; $query="SELECT * FROM $_DB[DIR] WHERE ( `flags` & ". DF_DIR_MADE | DF_V5 ." ) = ". DF_DIR_MADE ." ORDER BY `id` ASC;" ; echo ("$"."_DB[DIR] = $_DB[DIR]<br>"); echo (" DF_DIR_MADE = ". DF_DIR_MADE ."<br>" ); echo (" DF_V5 = ". DF_V5 ."<br>" ); echo("$query"); outputs this: $_DB[DIR] = Directory_database DF_DIR_MADE = 2 DF_V5 = 128 sw|ekt ? vrO_dE{rg{to{}dawc{ase WHERE ( `flags` & 2 I am an experienced coder, but this one has me stumped. I can't see how this corruption can occur on only that one variable, is this some bizarre quirk in php? and if so, how do I get around it? Quote Link to comment Share on other sites More sharing options...
James-A Posted November 8, 2013 Author Share Posted November 8, 2013 It looks to me like corrupted memory. but I know PHP has a few oddities, and am just curious if anyone else has encountered this particular one. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 8, 2013 Share Posted November 8, 2013 Yea I get the same result. However if I encase the bitwise or operation in parentheses then I get the correct output. $_DB[DIR] = Directory_database DF_DIR_MADE = 2 DF_V5 = 128 SELECT * FROM Directory_database WHERE ( `flags` & 130 ) = 2 ORDER BY `id` ASC; Quote Link to comment Share on other sites More sharing options...
James-A Posted November 8, 2013 Author Share Posted November 8, 2013 You may mark this resolved, It appears somehow the first part of my string was corrupted, perhaps Ctrl- characters sor something. Simply re-typing the whole thing made everything work fine. Quote Link to comment Share on other sites More sharing options...
James-A Posted November 8, 2013 Author Share Posted November 8, 2013 Yea I get the same result. However if I encase the bitwise or operation in parentheses then I get the correct output. $_DB[DIR] = Directory_database DF_DIR_MADE = 2 DF_V5 = 128 SELECT * FROM Directory_database WHERE ( `flags` & 130 ) = 2 ORDER BY `id` ASC; Thanks. I'll try that. Quote Link to comment Share on other sites More sharing options...
Solution DavidAM Posted November 8, 2013 Solution Share Posted November 8, 2013 Because of Operator Precedence (operators.precedence), the original code (with respect to $query) is equivalent to: $left = "SELECT * FROM $_DB[DIR] WHERE ( `flags` & ". DF_DIR_MADE; $right = DF_V5 ." ) = ". DF_DIR_MADE ." ORDER BY `id` ASC;"; $query = $left | $right; which produces the results you saw. Quote Link to comment Share on other sites More sharing options...
James-A Posted November 9, 2013 Author Share Posted November 9, 2013 Oh wow, now it makes sense. Thank you very much, I get that completely. 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.