I have 2 php files. I am unable to get B’s global variable from A’s static method:
A.php
class c_A
{ public static function f_A()
{ include_once( "B.php" ) ;
print f_B() ;
}
}
c_A::f_A( ); // only prints "B : "
B.php
$gvs = "global variable from B" ;
function f_B()
{ return "B : " . $GLOBALS[ "gvs" ] ;
}
$GLOBALS[ "gvs" ]is empty because you callingB.phpinside function. So$gvsvariable is not declaring as global variable. If you includeB.phpoutside of class atA.phpyou will get result:A.php