From: Don S. <do...@se...> - 2003-02-08 23:40:22
|
Came across a stumbling block and need a fresh set of eyes. I have 3 classes in my module (among others). Manager, Item, and Thing. Thing is a set of dynamic fields that could be in item. The Thing class defines the fields, not their values. So I thought it would be best to have my array of Things in the Manager class. So my Manager constructor it calls the sql to get all the things out of the database and populates an array of Thing objects. All is good. Now when the Item needs to get the list of Things to display forms or values it would just get the list like this: $this->mythings = $_SESSION["SES_MODULE_MANAGER"]->getThings(); Manager.getThings is defined as: function getThings() { // Things is the array of Thing object populated in the constructor return $this->_things; } I have echo statements that verify that the array return has the same number of items as the array in the Manager. However when I try to make function calls on the Thing objects in the array from my Item, I get error about call to member object on a non-object. Example would be if I tried this from my Item class: for($i=0; $i<count($this->mythings); $i++) $this->mythings[$i]->renderThing(); I had assumed it was pretty trivial, but can I, in fact, return an array of objects from the session? Don. |
From: Don S. <do...@se...> - 2003-02-09 00:06:26
|
I failed to note that Manager.getThings passes a reference to the Things array, not a copy. Otherwise the point of keeping the Things array in the session would be lost. But I have tried it with just the copy and I got the same error. Don. On Sat, 8 Feb 2003, Don Seiler wrote: > Came across a stumbling block and need a fresh set of eyes. > > I have 3 classes in my module (among others). Manager, Item, and Thing. > Thing is a set of dynamic fields that could be in item. The Thing class > defines the fields, not their values. So I thought it would be best to > have my array of Things in the Manager class. > > So my Manager constructor it calls the sql to get all the things out of > the database and populates an array of Thing objects. > > All is good. > > Now when the Item needs to get the list of Things to display forms or > values it would just get the list like this: > > $this->mythings = $_SESSION["SES_MODULE_MANAGER"]->getThings(); > > Manager.getThings is defined as: > > function getThings() { > // Things is the array of Thing object populated in the > constructor > return $this->_things; > } > > I have echo statements that verify that the array return has the same > number of items as the array in the Manager. However when I try to make > function calls on the Thing objects in the array from my Item, I get error > about call to member object on a non-object. Example would be if I tried > this from my Item class: > > for($i=0; $i<count($this->mythings); $i++) > $this->mythings[$i]->renderThing(); > > > I had assumed it was pretty trivial, but can I, in fact, return an array > of objects from the session? > > Don. > > > ------------------------------------------------------- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! > http://www.vasoftware.com > _______________________________________________ > Phpwebsite-developers mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpwebsite-developers > > > |
From: Don S. <do...@se...> - 2003-02-09 00:17:28
|
Nevermind. Note to children: When you grow up and want to be a php programmer, try not to be a careless idiot and re-use the variable name of your array of objects for an array of template data. Don. On Sat, 8 Feb 2003, Don Seiler wrote: > I failed to note that Manager.getThings passes a reference to the Things > array, not a copy. Otherwise the point of keeping the Things array in the > session would be lost. But I have tried it with just the copy and I got > the same error. > > Don. > > On Sat, 8 Feb 2003, Don Seiler wrote: > > > Came across a stumbling block and need a fresh set of eyes. > > > > I have 3 classes in my module (among others). Manager, Item, and Thing. > > Thing is a set of dynamic fields that could be in item. The Thing class > > defines the fields, not their values. So I thought it would be best to > > have my array of Things in the Manager class. > > > > So my Manager constructor it calls the sql to get all the things out of > > the database and populates an array of Thing objects. > > > > All is good. > > > > Now when the Item needs to get the list of Things to display forms or > > values it would just get the list like this: > > > > $this->mythings = $_SESSION["SES_MODULE_MANAGER"]->getThings(); > > > > Manager.getThings is defined as: > > > > function getThings() { > > // Things is the array of Thing object populated in the > > constructor > > return $this->_things; > > } > > > > I have echo statements that verify that the array return has the same > > number of items as the array in the Manager. However when I try to make > > function calls on the Thing objects in the array from my Item, I get error > > about call to member object on a non-object. Example would be if I tried > > this from my Item class: > > > > for($i=0; $i<count($this->mythings); $i++) > > $this->mythings[$i]->renderThing(); > > > > > > I had assumed it was pretty trivial, but can I, in fact, return an array > > of objects from the session? > > > > Don. > > > > > > ------------------------------------------------------- > > This SF.NET email is sponsored by: > > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! > > http://www.vasoftware.com > > _______________________________________________ > > Phpwebsite-developers mailing list > > Php...@li... > > https://lists.sourceforge.net/lists/listinfo/phpwebsite-developers > > > > > > > > > ------------------------------------------------------- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! > http://www.vasoftware.com > _______________________________________________ > Phpwebsite-developers mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpwebsite-developers > > > |