473,396 Members | 1,972 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,396 software developers and data experts.

Recursive "single-referenced" methods and static variables

[PHP]
class DepartmentTree {

function &buildTree($id) {
static $html;
if (!isset($html)) {
// DO STUFF HERE TO $html
}
// DO MORE STUFF
if ($condition_is_met) $this->buildTree($newID);
$this->html = $html;
}

}
[/PHP]

The above (and greatly paraphrased from the 100-line actual class)
class and method, in its real form, totally works inasmuch as it
successfully always creates an HTML hierarchial tree of departments
mapped with child departments. I have no problem with this.. as long
as I only use the class once.

However, there is a case where I need the entire contents of the
departments table dumped out into a resultset, and to do that I
figured I would just loop through a query of records that have no
parent ID; each id in each row I seed into $tree->buildTree():

[PHP]
for ($i = 0; $i < @sizeof($result); $i++) {
$tree->buildTree($result[$i]->id);
$this->deptArray += $tree->convert_to_array();
$tree->clearTreeHTML();
}
[/PHP]

The "convert_to_array()" method will convert the contents of
$this->html from HTML content to an array, keeping the original
hierarchial order; the "clearTreeHTML()" method will set $this->html
to NULL or "".

Problem is, it does not do that, because apparently "static $html"
keeps an instance of it running in the single-referenced instance of
"buildTree" method.

Based on how best I can explain my problem, and sorry I can't explain
it any better w/o dumping the actual code line by line, how have you
all figured out the best way to generate multiple, unique instances
from a single-referenced method that uses a static local variable?

Thanx
Phil
Jul 17 '05 #1
0 1559

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: girish | last post by:
In my XML document, some node attributes data contains both single quot and double quote characters, such as <input msg="Hello "World", What's up"/>. The double quotes are in form of escape...
3
by: Martin Ink | last post by:
I have a program linked to an .exe and this program is started from an other program. I would like to control the execution of the program so that the program only runs 'single threaded'. I don't...
3
by: Paul Janssen | last post by:
Hello! Can anyone help me out with the following situation: (a) a single query with 550 id's in the IN-clause resulting into 800+ seconds; (b) 550 queries with a single id in the IN-clause...
1
by: sarak13_2000 | last post by:
I am using Access2000 . In a query window, after selection of a group of records using aggregate function "group by", I want to retrieve only one record from each group including ungrouped fields...
0
by: Laharl | last post by:
This is what I am trying to do: public abstract class A : ISerializable { public A(SerializationInfo info, StreamingContext context){} public void GetObjectData(SerializationInfo info,...
2
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the...
51
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and...
5
by: David Thielen | last post by:
Hi; Is there a way to do <%# switch (Eval("prop")) ... where the case statements are the text to put on the page? -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com
6
by: Nirjhar Oberoi | last post by:
Hi, Can you add two numbers using a Single Variable? :-) If yes then show me the code!!! Regards Nirjhar
2
by: Chris Thomasson | last post by:
I was wondering if the 'SLINK_*' and 'SLIST_*' macros, which implement a simple singly-linked list, will produce _any_ possible undefined behavior: ____________________________ #include...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.