Jump to content

Bizarre error


James-A

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
https://forums.phpfreaks.com/topic/283729-bizarre-error/
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
https://forums.phpfreaks.com/topic/283729-bizarre-error/#findComment-1457572
Share on other sites

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
https://forums.phpfreaks.com/topic/283729-bizarre-error/#findComment-1457604
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.