Re: Listing objects
- From: Lüpher Cypher <lupher.cypher@xxxxxxxxxxx>
- Date: Fri, 30 Dec 2005 15:05:08 GMT
Peter Fox wrote:
Following on from Lüpher Cypher's message. . .Hi,
Suppose we have a hierarchical class structure that looks something like this:Sorry, I lost the plot half way through.
Your objects can be
1 - nesting : object has a 'what are my children' and 'who is my parent' functionality.
2 - pointing : eg object has a 'these are my siblings' or 'previous/next' functionality
3 - dictionary entries : object in some container is discoverable by name
It is more of a [1] and [3] :)
[1] for I do have a tree-like structure of objects. I have $parent (for all objects) and $owner (for objects that are of subclasses of some class) properties so, I can go bottom-up. I also do have children array for objects that have owner so, I can go top-down.
[3] for I am trying to have a global associative array that has unqiue object names as keys and object references as values.
Variations and combinations of course apply. BUT every object exists in some context. I /think/ you might be trying to get A's to point-to/own B's where more than one A could be the parent of a B. Eg
"Sally is daughter of Jean"
"Geoffrey is son of Teddy"
"Sally is daughter of Teddy" // Only one Sally! J+T are married.
In this case[1] create an array of children and point to elements in that array from your parent objects.
eg $child['Sally'] = new ChildObj(.....);
then $Jean->AddChild('Sally') // just a key name or index
or $Jean->AddChild($child['Sally']) // inside the routine do $myKids[] = & $NewChild
where $NewChild is the function argument.
[1] If in this example children can be parents then you should be looking at a single universal 'person' class with the necessary links.
I do have a universal class :) Say,
class Object var $name; var $owner; var $children[];
Now,
class A extends Object class B extends Object
A's can be owned by A's and/or B's, B's can have many A's and/or B's B's can be owned by A's and/or B's and can have many A's and/or B's as well.
One of the things I am trying to do is to have global references to all Objects:
global $objects; $objects = array();
function Object() {
global $objects;
... assign name ...
$objects[$this->name] = &$this;
}However, if a property of some Object changes, $objects[$object_name] still has the "old" object. I assume $objects[$object_name] does not reference the object then, rather has a copy of it. So far I was unable to solve this.. By the way, this will work:
$obj = new Object(); $objects[$obj->name] = &$obj;
if it is executed outside any function and any class..
luph .
- References:
- Listing objects
- From: Lüpher Cypher
- Re: Listing objects
- From: Peter Fox
- Listing objects
- Prev by Date: Re: Listing objects
- Next by Date: Re: Users/permissions/files - LAMP
- Previous by thread: Re: Listing objects
- Next by thread: Re: Listing objects
- Index(es):
Relevant Pages
|