Where to put the functions in plugin?

A user defined function cannot work in form view page.

I test it with the following test function, I put it in different files in my plugin's directory,  it gives '15' on the files that locate in my plugin root, i.e. index.php, start.php, it gives '5' on other files..

function test($num){
global $num;
  $num += 10;
}
$num =5;
test($num);
echo $num; // 5

It seems the global variable cannot be read. Do I miss something on initializing the plugin? Or Elgg has a framework limit?