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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:46:11+00:00 2026-05-27T19:46:11+00:00

I have a PHP class method which is using a static function from with

  • 0

I have a PHP class method which is using a static function from with a another class. How do i enable that static function to modify variables within the calling class.. Example as follows:

PARENT:

class sys_core
{
   public $test = 'no';

   // --------------------
   public function __construct()
   {
   }

   // --------------------
   public function init()
   {
      sys_loader::load_config('123');
      print $this->test;
   }

   // --------------------
   // --------------------
   // --------------------
   // --------------------
   // --------------------

} // END Class

STATIC CLASS

class sys_loader
{
   private $registry = array();

   // --------------------
   public static function load_config($file)
   {
      $this->test = 'yes';
   }

   // --------------------
   // --------------------
   // --------------------
   // --------------------

} // END Class

ERROR:

Fatal error: Using $this when not in object context
  • 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-27T19:46:11+00:00Added an answer on May 27, 2026 at 7:46 pm

    As I see it, sys_loader can modify sys_core’s $test 3 ways:

    1) sys_loader is passed a reference to sys_core->test,
    2) sys_loader returns a new value for it or
    3) equip sys_core with a setter for $test and pass sys_loader a reference to sys_core.
    With that reference, sys_loader can access whatever variables and functions sys_core allows.

    Here are the bits I changed/added to make #3 work:

    Example use:

    $sc = new sys_core();
    $sc->setConfigFile('123');
    $sc->init();
    

    Output:
    123yes

    class sys_core

    // new
    private $configFile = null;
    
    // new
    function getConfigFile() {
      return $this->configFile;
    }
    
    // new
    function setConfigFile($value) {
      $this->configFile = $value;
    }
    
    // new
    function setTest($value) {
      $this->test = $value;
    }
    
    
    public function init()
    {
    // sys_loader::load_config('123');
      sys_loader::load_config($this);
      print $this->test;
    }
    

    class sys_loader

    // public static function load_config($file)
    public static function load_config($caller)
    {
    // $this->test = 'yes';
      $caller->setTest('yes');
    // new, example
      $config = $caller->getConfigFile();
    // new, example
      echo $config;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does PHP have a method of having auto-generated class variables? I think I've seen
I have certain PHP class methods that access external variables. These variables are not
I have a PHP script which calls methods from a class I have written.
I have a main class which initializes another class in a function of main
i have a php class method which determines whether if a class property have
I have a class structure in PHP which I am using to allow for
I have a PHP class with a method. In the base class (it's more
I have a PHP class that creates a PNG image on the fly and
I have a PHP class that stores a complex multidimensional array, and rather than
I have a php class that generates a map image depending on my db

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.