Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:18:34+00:00 2026-05-27T22:18:34+00:00

I have one main class main, which I use to store the configuration and

  • 0

I have one main class “main”, which I use to store the configuration and a few objects. However, I am unable to access the objects & variables in a class which extends main, through $this.

Here is some of my main class:

<?php
class main{
    // the configuration vars
    public $config = array();
    // the current user variables
    public $uid; // contains the user ID
    public $gid; // contains the group ID
    // database variables
    public $DB; // contains the connection
    public $query_id; // contains the query ID
    public $query_count; // how many queries have there been?
    // cache variables
    public $cache;
    // start up functions
    public function startup(){
        // first, set up the caching
        if(function_exists('memcache_connect') AND $this->config['use_memcache'] == true){
            // start up memcache
            require_once('memcache.class.php');
            $this->cache = Cache::getInstance();
        }
        // now, set up the DB
        $this->connectToDatabase();
        // now, set up the user session
        $this->setUserSession();
        // are we logged in? If so, update our location
        if($this->uid > 0){
            // update location
            $this->updateUserSession();
        }
    }

Here is an example of another class

<?php
class user extends main{
        public function viewProfile($uid){
                exit($this->config['session_prefix']); // displays nothing
                if($this->cache->exists('key')){ // fails

The $config value is correctly set up, and I can read it within main but not any sub class.
The $cache->exists object just results in Call to a member function exists() on a non-object.

On index.php, the classes are loaded and set up. The Main class is setup first, and the startup function is called. The configuration array is passed before startup is called.

Can anyone suggest how I can fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:18:35+00:00Added an answer on May 27, 2026 at 10:18 pm

    Are you sure your array is correctly set up.

    This simple test works for me:

    <?
    class main {
        public $test = "Woot";
    }
    
    class test extends main {
        public function __construct() {
            echo $this->test;
        }
    }
    
    $t = new test();
    

    Just for testing purposes, add a variable $test like in my example to the class main and try to echo it in the user constructor.

    I would check if your cache is really set up correctly.
    Probably the error is in this if statement:

    if(function_exists('memcache_connect') AND $this->config['use_memcache'] == true){
    

    One of these two conditions isn’t met, so your $cache variable won’t get initialized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class PanelFormes that extends JPanel, which I use as a container.
In the application I am writing, I have a main class which extends the
I have one main parent swf that loads several other swfs. If something happens
I have one main outstanding issue, I know now how to databind to lists
I have WPF Application where I have One main form and other user controls
I have a WinForms TreeView with one main node and several sub-nodes. How can
When I have one app.config in my main project I always have to duplicate
With a distributed application, where you have lots of clients and one main server,
I have an application that has two threads. The first one (the main thread)
I'm using the jQuery Validation JS I have two contact forms, the main one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.