473,322 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Can't change an object variable from outside the class?

SamKL
27
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.
Jan 30 '08 #1
1 2544
Try this:
Expand|Select|Wrap|Line Numbers
  1. function &findNode( $search, $searchby = X_ID, $start = TRUE )
Not sure if it will work, but I hope it helps.

Regards,
Tom
Jul 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: lawrence | last post by:
I posted before, but have now narrowed my problem down to this method. At the start of the method, I test to make sure that I have a resource, a pointer to data returned from a database. This test...
6
by: Buddy Ackerman | last post by:
I created a simple class: Public Class MyTestClass Public Test() As String End Class I tried to assign some values to the array Test() and display them like this:
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
5
by: Steven | last post by:
I'm using C# as code-behind for my aspx pages. How can I bind pages.. so that both the pages can use the functions, variables, controls .. between each other. eg., if I declare function scope()...
5
by: joeblast | last post by:
I have a Web service that gets the financial periods and hold a reference to a disconnected dataset built at initialization. Web methods work on the dataset inside the web service. Everything is...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
8
by: downwitch | last post by:
Either I don't understand (entirely possible), or there's no way to copy parts of a class hierarchy from one instance to another. Say I have a class called Foo, and it contains, among other...
13
by: Andy Baxter | last post by:
Can anyone recommend a good online guide to using objects in javascript? The book I bought (DHTML Utopia) suggests using objects to keep the code clean and stop namespace clashes between different...
12
by: jeremito | last post by:
Please excuse me if this is obvious to others, but I can't figure it out. I am subclassing dict, but want to prevent direct changing of some key/value pairs. For this I thought I should override...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.