Jump to content

Recommended Posts

I need to create an object of type class1 that as one ot its properties has an array of objects of type class2. Class2 objects also need to have a property that is an array of objects of class3. For some reason, my code is not working as I'd expect... Am I using constructors and destructors properly? The structure of my program is similar to the next:

 

for(some condition){

    $object1 = new Class1($arguments);

    $object1->SomeOperation();

}

$pnr->__destruct();

 

class Class1

{

    private static $properties; //which will be an array of class2 objects

    public function __construct($p){

        $this->setProperties($p);

    }

    public function __destruct(){

        self::$properties = null;

    }

    public function setProperties($args) {

        $i = 0:

        while(some condition){

            $class2object = new Class2($arguments);

            self::$registros[$i] = $nuevoRegistro;

            $i++;

        }

    }

}

       

class Class2

{

    private static $properties; //which will be an array of class2 objects

    public function __construct($p){

        $this->setProperties($p);

    }

    public function __destruct(){

        self::$properties = null;

    }

    public function setProperties($args) {

        $i = 0:

        while(some condition){

            $class2object = new Class2($arguments);

            self::$registros[$i] = $nuevoRegistro;

            $i++;

        }

    }

}

 

class Class3

{

    private static $properties; //which will be an array of class2 objects

    public function __construct($p){

        $this->setProperties($p);

    }

    public function __destruct(){

        self::$properties = null;

    }

}

 

Plese, do help me!

don't use static.. you're misusing the static keyword in your examples.. removing the static keywords will resolve all your problems. you can't use a static declaration through an instantiation, you'd need to use it through the object itself with the scope resolution operator (::)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.