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

  • Home
  • SEARCH
  • 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 8776437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:03:24+00:00 2026-06-13T19:03:24+00:00

I have following setup. index.php require_once common.php; … common.php … $obj = new MyClass;

  • 0

I have following setup.

index.php

   require_once "common.php";
   ...

common.php

   ...
   $obj = new MyClass;
   require_once "config.php"
   ...

config.php

   ...
   require_once "settings.php";
   ...

settings.php

   $obj->dostuff = true;
   ...

When i open index.php i get: Strict Standards: Creating default object from empty value in settings.php on 3

If i put $obj->dostuff = true; inside config.php it does not produce error message.

Can someone explain why i get this error? I am not asking how to fix it just understand why.

EDIT: My bad i had 2 config.php classes for each part of site and i only changed something in one of them leaving old include order in another now it works fine after it all loads in correct order.

  • 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-13T19:03:26+00:00Added an answer on June 13, 2026 at 7:03 pm

    If $obj is meant to be a system wide globally accessible object, you can you use the singleton pattern to access from anywhere:

    class MyClass
    {
        protected static $_instance;
    
        static function getInstance()
        {
            if (null === self::$_instance) {
                self::$_instance = new self();
            }
            return self::$_instance;
        }
    }
    

    You can then create your methods in this class. To get the object itself simply call:

    $obj = MyClass::getInstance();
    

    Additionally, if you just want to call one of its methods but theres no need to return anything:

    MyClass::getInstance()->objectMethod();
    

    I find this to be a very efficient way to organize integral singleton based system wide operations.

    In practice, my project uses this to get configuration from anywhere in the system:

    class syConfig
    {
        protected static $_instance;
    
        private $_config;
    
        static function getInstance()
        {
            if (null === self::$_instance) {
                self::$_instance = new self();
            }
            return self::$_instance;
        }
    
        public function load($xmlString)
        {
            $xml = simplexml_load_string($xmlString);
            $this->_config = $xml;
        }
    
        public function getConfig()
        {
            return $this->_config;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML form POSTing to the following index.php: <?php require_once(/home/full/path/to/included/file.php); ?> And
I have a cron task setup to run the following: php /var/www/vhosts/examplesite.com/index.php cron processCategoryItemCount
I have the following setup for phpmyadmin: <Directory /usr/share/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php Order
I have the following setup: Web.config has customErrors mode=Off Global.Application_Error() event calls a custom
Currently I have the following fulltext index setup: fulltext on: Number - Name -
I have following setup, but when I put 1024 and replace all 512 with
I have following models setup in my Django application class School(models.Model): name = models.TextField()
I have the following setup: Table: Question QuestionId Table: QuestionTag QuestionId TagId Table: Tag
I have the following setup, and I need to know how to persist state.
I have the following setup, and the empty view text doesn't show up... protected

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.