diegueins Posted January 27, 2010 Share Posted January 27, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/190036-is-it-ok-to-have-arrays-of-objects-as-a-private-property/ Share on other sites More sharing options...
RussellReal Posted January 28, 2010 Share Posted January 28, 2010 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 ( Quote Link to comment https://forums.phpfreaks.com/topic/190036-is-it-ok-to-have-arrays-of-objects-as-a-private-property/#findComment-1002737 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.