The Little Guy Posted August 3, 2011 Share Posted August 3, 2011 I have an instance of a class, how can I make that global without having to define it in all my functions? Here is an example I have been trying to get to work: My Class file: <?php class phpLive{ // Some methods and properties here } $phplive = $_live = $live = $_ = new phpLive(); global $live; ?> The Page: <?php require_once 'phpLive.php'; $live->get_http("http://google.com")->callback(function(){ echo $live->title; }); ?> But the above code gives me this error: Notice: Undefined variable: live in C:\wamp\www\phpLive\index.php on line 13 Notice: Trying to get property of non-object in C:\wamp\www\phpLive\index.php on line 13 I don't want to have to place "global $live" inside each function, so is there a way for me to access it? BTW I have tried these as well without success: echo $this->title; echo self::title; Quote Link to comment https://forums.phpfreaks.com/topic/243725-custom-superglobal/ Share on other sites More sharing options...
IrOnMaSk Posted August 3, 2011 Share Posted August 3, 2011 define it outside and above the function... and you can only call it from within the page anywhere but not from different page... Quote Link to comment https://forums.phpfreaks.com/topic/243725-custom-superglobal/#findComment-1251417 Share on other sites More sharing options...
IrOnMaSk Posted August 3, 2011 Share Posted August 3, 2011 maybe this?http://php.net/manual/en/language.variables.scope.php probly not Quote Link to comment https://forums.phpfreaks.com/topic/243725-custom-superglobal/#findComment-1251420 Share on other sites More sharing options...
Alex Posted August 3, 2011 Share Posted August 3, 2011 http://www.php.net/manual/en/reserved.variables.globals.php Quote Link to comment https://forums.phpfreaks.com/topic/243725-custom-superglobal/#findComment-1251423 Share on other sites More sharing options...
The Little Guy Posted August 3, 2011 Author Share Posted August 3, 2011 That won't work, as I have to get the value before I can use it, I would like it to just be available. I have tried this, but it isn't working. ini_set("runkit.superglobal", "live"); ini_set("runkit.internal_override", "1"); Quote Link to comment https://forums.phpfreaks.com/topic/243725-custom-superglobal/#findComment-1251424 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.