Array of Instances Inside Constructor

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Can anyone help me figure out how to make a class keep an array of all
of its instances?  This was my first and obvious first shot...

class A
    function A()
        static $a = array() ;
        $this->array =& $a ;

        $this->array[] =& $this ;

But, if I make changes to the instance contents (not included above)
they are lost when I eventually try to use the array of references.
Quoted text here. Click to load it
like this because of when memory is actually created by PHP.  (It's no
problem if I want to store an array of references AFTER the new
operator has returned the instance but I am trying to make it
transparent and put all of this inside the constructor where it should

Any tricks or workarounds are appreciated!

Re: Array of Instances Inside Constructor

phpdevkit wrote:

Quoted text here. Click to load it

Try this:

class Foo
        public static $arr = [];
        public function __construct() {
                self::$arr[] = $this;

-- Fred of UrlBit.Us
-- http://UrlBit.Us - Bite those URLs down to size!

 Posted Via Premium Usenet Newsgroup Services

Site Timeline