Because you forgot the scope of func_1. So when you include your define this is how your code appears to PHP
function func_1() {
$some_global_var = 'abc'; // <- this is inside the scope of the parent function!
function func_2($var) {
global $some_global_var;
echo $some_global_var.$var;
}
$somevar = 'def';
func_2($somevar);
}
You're doing it inside func_1. So the variable was never really available in the global scope. If you defined $some_global_var = 'abc'; outside, then it's in the global scope.
What you should do is inject this as an argument instead. Globals are a bad practice
function func_1() {
$some_global_var = 'abc';
function func_2($var, $var2) {
echo $var2 . $var;
}
$somevar = 'def';
func_2($somevar, $some_global_var);
}
$some_global_var = 'abc';might but must not set a global variable (in your case it is a local variable), also include_once will make the assignment to only run once.