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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.