ShoeLace1291 Posted September 22, 2012 Share Posted September 22, 2012 So, I am using SMF and I want to use the SSI features within my regular site. However, I want to do this within a class that I am creating. I want to include the file at the top of the page so that I can use the $context array that contains all of the information I need in every method I create... without having to include the file within every new method. Here's what I have so far: <?php include('/../../forums/SSI.php'); class smf { var $username; var $is_guest; var $is_logged; var $is_admin; var $is_mod; var $email; var $name; var $avatar; function __construct(){ $this->username = $context['user']['name']; $this->is_guest = $context['user']['is_guest']; $this->is_logged = $context['user']['is_logged']; $this->is_admin = $context['user']['is_admin']; $this->is_mod = $context['user']['is_mod']; $this->email = $context['user']['email']; $this->avatar = $context['user']['avatar']; } function context(){ return $context; } } I get an undefined variable method every time I call the context variable. Quote Link to comment https://forums.phpfreaks.com/topic/268651-including-files-before-classes/ Share on other sites More sharing options...
kicken Posted September 22, 2012 Share Posted September 22, 2012 global level variables are not automatically available within functions. In order to import them you need to use the global keyword. It's preferable not to use globals though and instead pass them in as a parameter when you call a function (or construct your class). Quote Link to comment https://forums.phpfreaks.com/topic/268651-including-files-before-classes/#findComment-1379960 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.