Jump to content

Bizarre error


James-A
Go to solution Solved by DavidAM,

Recommended Posts

$_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?

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

  • Solution

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.
Link to comment
Share on other sites

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.