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 8305849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:12:38+00:00 2026-06-08T18:12:38+00:00

One more try at this. I’ve already had my previous question down voted. I

  • 0

One more try at this. I’ve already had my previous question down voted.

I am loading a class through a class that is never instantiated via a static method. The class I am loading however is supposed to be instantiated but I suspect that execution never gets that far. There is nothing static in this class, but php keeps throwing:

**Fatal error: Using $this when not in object context**

Here is the class in it’s entirety:

class Config{


    public $_config;



    public function load()
    {
        $modules = array();
        $modules = scandir(MOD);
        $n = count($modules);
        for($i=0;$i<$n;$i++)
        {
            if($modules[$i]==='.'||$modules[$i]==='..'||strpos($modules[$i],'.'))
            { unset($modules[$i]); }

        }
        $modules = array_values($modules);
        $m = count($modules);

        for($i=0;$i<$m;$i++)
        {
            $mod = $modules[$i];
            $this->_config[$mod] = array();// **Error thrown here.**
            $cfgfiles = scandir(MOD.DS.$mod.DS.'config');
            $num = count($cfgfiles);

            for($i=0;$i<$num;$i++)
            {
                if($cfgfiles[$i]==='.'||$cfgfiles[$i]==='..')
                    { unset($cfgfiles[$i]); }
            }

            $cfgfiles = array_values($cfgfiles);
            $k = count($cfgfiles);

            for($j=0;$j<$k;$j++)
            {
                include(MOD.DS.$mod.DS.'config'.DS.$cfgfiles[$j]);
                $modcfg = substr($cfgfiles[$j], 0, -4);
                $this->_config[$mod][$modcfg] = array();
                $this->_config[$mod][$modcfg] = $cfg;
            }

        } 
        return $this->_config;
    }

}

More information outlining my problem can be found here:

https://stackoverflow.com/questions/11653956/using-this-when-not-in-object-context-but-supposedly-i-am

Ok, as requested, here is the code that calls this class and yes, it is a static function. This is what I was wondering about, but the fact that the function in the other class was static did not seem to have any effect on the loading of other classes, only this one.

public static function init()
{
    $farray = scandir(SYS);

    for ($i=0;$i<count($farray);$i++)
        { if(strpos($farray[$i],'.php'))
        {
        $item = $farray[$i];
        require (SYS.DS.$item);
        $className = substr($item, 0, -4);
        self::$_names[] = $className;
        $obj = new $className();
        self::$_objs[] = $obj;
        self::$_classes = array_combine(self::$_names, self::$_objs);
        }
    }
}


public static function getClass($class)
{
    if(isset(self::$_classes[$class]))
        { return self::$_classes[$class]; }
    else
        { return false; }
}

Ok, I added a debug_backtrace() at the line just before the error($this->_config[$mod]=array()) and this is what I get, but I do not understand what it means.

array(2) 
 { [0]=> array(6) 
{ ["file"]=> string(25) "C:\xampp\htdocs\framework\fw.php" 
["line"]=> int(45) 
["function"]=> string(4) "load" 
["class"]=> string(6) "Config" 
["type"]=> string(2) "::" 
["args"]=> array(0) { } } 

[1]=> array(6) 
{ ["file"]=> string(26) "C:\xampp\htdocs\index.php" 
["line"]=> int(31) 
["function"]=> string(4) "init" 
["class"]=> string(2) "Fw" 
["type"]=> string(2) "::" 
["args"]=> array(0) { } } }

Ok, I’ve done everyone who responded to this question a dis-service. It turns out that I was indeed inadvertently making a static method call to Config::load in Fw::init. Because I had made so many revisions and worked on it until I was bleary eyed I unknowingly ended up with two different version of the same class, one on my server and one in my editor.

I am now going off to learn how to use a source control application.

  • 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-06-08T18:12:39+00:00Added an answer on June 8, 2026 at 6:12 pm

    The most likely thing going on here is that you’re calling the Config::load() method statically. This type of code will result in the error you quoted in your question:

    Config::load()
    

    You can fix it by instantiating an object and calling the load() method on the instance. Like this:

    $config = new Config();
    $config->load();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here one more basic question asked in MS interview recently class A { public
Hey guys I have one more question lol. I am using a script that
This was a question in one my friend's programming class. Q. How do you
Lets try this one more time. I'm posting this to get 2 questions answered
Hello guys i try to get an object global/persistent over more than one php
Is possible to catch more then one exception in the same catch block? try
I want to pass more than one variable to other web pages. I try
One more question about most elegant and simple implementation of element combinations in F#.
UPDATED: Added one more question (Question #4). Hi all, I'm building myself a custom
This is yet one more of those how to switch from running with a

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.