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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:05:12+00:00 2026-05-27T04:05:12+00:00

Well, I was completely re-coding my advanced IRC bot to allow all methods and

  • 0

Well, I was completely re-coding my advanced IRC bot to allow all methods and properties to be available in $this, without the need for long chains like $this->Configuration->someProperty, etc. My code is split over several files, each containing its own class. For this to be possible, I was using __set and __get to provide access to these properties of other classes.

While doing this, I hit some trouble with one of my array’s. Upon further experimenting in a blank PHP file, I’ve determined it must be either a PHP bug or unexpected behaviour. Note, I haven’t traced the problem to __get or __set, it seems to simply be a problem with extends.

<?php
new test();

class test
{
    public $oInstance;
    public $aSettings = array
    (
        'Bot' => array(),
        'Server' => array(),
        'Logs' => array(),
        'Extensions' => array(),
        'Other' => array('Time' => '')
    );

    public function __construct()
    {
        $this->setit();
        //$this->aSettings['Other']['Time'] = time();
        $this->oInstance = new test2();
    }

    public function setit()
    {
        $this->aSettings['Other'] = time();
    }

    public function __call($sFunction, $aArgs)
    {
        if(method_exists($sValue, $sFunction))
        {
            return call_user_func_array(array($sValue, $sFunction), $aArgs);
        }
    }

    public function __get($sName)
    {
        if(property_exists('test2', $sName))
        {
            return $this->instance->$sName;
        }
    }

    public function __set($sName, $mValue)
    {
        if(property_exists('test2', $sName))
        {
            $this->instance->$sName = $mValue;
            break;
        }
    }
}

class test2 extends test
{
    public function __construct()
    {
        var_dump($this->aSettings);
    }
}
?>

I stripped the $aSettings array from my actual bot code, the rest is experimental code. Anyway, everything in the code is basically the same.

As the code shows, test2 extends the test class. This means it should inherit all the public properties of test. It does inherit it fine.. the problem starts when I assign a value to $aSettings. The changes seem to take no effect at all. When $aSettings[‘Other’][‘Time’] is var_dump’d it still shows it’s original set value of ”/nothing, but the setit() method should have set the value to time(). Here’s the really weird thing: var_dump’ing $aSettings[‘Other’][‘Time’] in the setit() method shows that it has been set to time(), but any time it is var_dump’d in test2, it shows the original set value.

I really don’t know what is causing this.. but I need a fix if I’m gonna continue on with my bot. I’ve tested this on the latest PHP version (5.3.8) on Mac, Windows and Linux, all yielding the same result.

  • 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-27T04:05:13+00:00Added an answer on May 27, 2026 at 4:05 am

    First, PHP is pretty mature and odds are if you’re doing something simple (like manipulating arrays inside a class), you probably aren’t encountering a bug, but are doing something wrong.

    You must be confusing the var_dump output. The first var_dump you see in my paste below is because of the constructor of class test2, which is instantiated in the constructor of test. This var_dump will ALWAYS output the default value of $aSettings['Other']['Time'], because:

    1. The constructor of test2 does not call the parent constructor (which it can’t as that’ll be a huge memory leak since objects will be recursively created)
    2. The object of test2 created in the constructor of test never has any operations performed on it to change the $aSettings['Other']['Time'] value (i.e. calling setit() or setting the property through __set().
    3. When an object of test2 is instantiated, it inherits the default values of the $aSettings array from test.

    The second is the var_dump of the object created from instantiating test, which clearly shows that $aSettings['Other']['Time'] is modified to time().

    See the following paste, and you’ll see that the object from class test has the correct value for $aSettings['Other']['Time'].

    http://codepad.org/lsL3mObm

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

Sidebar

Related Questions

Well behaved windows programs need to allow users to save their work when they
Well, I completely get the most basic datatypes of C, like short, int, long,
This seems like it is completely straightforward, but my brain isn't working very well
This is a bit of a weird one, and I could well be coding
Well, I'm completely new to JavaScript. Can you please tell me what type of
Well, I don't know if I'm completely wrong, but I really can't find a
Well, after a long time writing .net programs in C# I started to feel
Well, this is my first post here and really enjoying the site. I have
I am completely new to ASP.NET and VB as well as C#. I am
we have an app which is available for ipad, iphone, android as well as

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.