Hey, I'm no expert on PHP, and I have somewhat of an understanding of object oriented code. Anyway, getting right to the problem.
I'm using PHP4, so base it off of that. Basically I have 2 classes in this code.
Link_Structure, which is composed of Node classes (it's a linked list data structure), and of course the Node class.
In class Node:
[PHP]function setActive( $i ) { $this->_data[X_ACTIVE] = $i; }[/PHP]
This function is designed to set the array within the object. X_ACTIVE is a constant defined as the index of the array where the ACTIVE variable is stored
In class Link_Structure:
[PHP]function findNode( $search, $searchby = X_ID, $start = TRUE )[/PHP]
This function finds a node in the structure that matches $search, and uses $searchby to match by array field (in this case, the default matching field is the ID field). $start simply designates whether to reset the search pointer or not, since this is a recursive function, it starts from the beginning of the object by default. Ultimately, findNode returns $this->_np, which is a variable in Link_Structure that points to a Node object. When it finds a Node, it returns the value of $this->_np at it's current location.
Now here's the problem. Both of these functions work, I've tested them thoroughly, and they do what they're designed to do.
[PHP]$test = new Link_Structure("linkstruct.txt");
$find = &$test->findNode("tech");
$find->setActive(1);
$test->buildList();[/PHP]
This is the code I've used to test it out. $test is a new Link_Structure object using the specified .txt file to create it's linked list.
$find then gets a reference to a Node object within the structure using findNode (it definitely works properly, as I can call ->getData and it will print out the array of that node correctly. setActive(1) also works, as I use it during the construction of the linked list.
Now here's the issue
[PHP]$find->setActive(1);[/PHP]
Does set the Active field in that node to 1, but only seems to do it in the instance of $find... when I run buildList(), which draws a UL representation of the structure, any nodes that are specified as active should be bolded. Apparently the actual instance of the link structure is not affected by the outside $find->setActive() call, but it works when I call it during construction only.
Is my syntax wrong? Should I be using another method to carry this out? I basically want to be able to use findNode to return the node object, and be able to call setActive from that variable to change the actual structure data from outside the class constructor.