Jump to content

Including Files Before Classes


ShoeLace1291

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/268651-including-files-before-classes/
Share on other sites

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).

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.