dsdsdsdsd Posted March 23, 2012 Share Posted March 23, 2012 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" ] ; } any thoughts? thanks, Shannon Quote Link to comment https://forums.phpfreaks.com/topic/259585-trying-to-include-a-php-file-from-within-a-static-class-function/ Share on other sites More sharing options...
scootstah Posted March 23, 2012 Share Posted March 23, 2012 What exactly are you trying to do? Using globals is doing it wrong. Quote Link to comment https://forums.phpfreaks.com/topic/259585-trying-to-include-a-php-file-from-within-a-static-class-function/#findComment-1330587 Share on other sites More sharing options...
dsdsdsdsd Posted March 23, 2012 Author Share Posted March 23, 2012 I figured it out ... effectively what I was doing is the same as this: function M ( ) { //--vvvvv-- from the include $gvi = 10 ; function N( ) { global $gvi ; return $gvi ; } //--^^^^^-- from the include print "N : " . N() . "<br/>" ; print "N : " . $gvi . "<br/>" ; } M() ; and of course $gvi is NOT in the global scope in this example ... Quote Link to comment https://forums.phpfreaks.com/topic/259585-trying-to-include-a-php-file-from-within-a-static-class-function/#findComment-1330604 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.