Re: objects in functions?

From: Date: Sun, 11 Mar 2001 01:26:13 +0000
Subject: Re: objects in functions?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-43352@lists.php.net to get a copy of this message
> Hi, > I want to make a recursive function generating a hierarchy using a class. > > The following code works fine when I don't wrap the function around it, > but when I do it fails. I can't figure out why... > I'm thinking I may need to make some vars global, or maybe you can't use > objects inside functions? (No, couldn't be) If following code is all code that you make a tree node. Your guess is rgiht. Take a look at http://www.php.net/manual/en/language.variables.scope.php You also better to read reference section carefully (espacially you have been programminged in C/C++) http://www.php.net/manual/en/language.references.php regards, Yasuo Ohgaki > > Here's the code: > ......... > $root = $tree->open_tree ($title, ""); > > function generate_nodes($id) { > > $sql = "select * from hierarchy where parent = $id"; > $res = mysql_debug_query($sql); > while ($row = mysql_fetch_array($res)) { > $node = "node" . $count; > $$node = $tree->add_folder ($root, $row["name"] . " <font > size=1>" . $row["id"] . "</font>", ""); > > $count++; > } > } > generate_nodes($id); > ........ > Thanks for any hints... > Peter > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > http://liga1.com: building multiple language/culture websites > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#43352) next »