eval'd code is bombing... anybody know of a tree data structure I could use? 
Author Message
 eval'd code is bombing... anybody know of a tree data structure I could use?

Hi All,

When I try to run eval('$this->menuArray[2][1] = new menuObj;'), I get
the following warning:

Warning: Cannot use a scalar value as an array in
/home/HE/web_develop/company_home/www/cgi-bin/includes/menuCL.inc(130) :
eval()'d code on line 1

Any attempt to use the object $this->menuArray[2][1] fail, as it wasn't
able to properly create the object. Here's the weird part - copying and
pasting that code into my file lets it execute perfectly fine.

I'm trying to create an array of menu objects (really just a data
object), that is stored in a master control menu object. I want it to be
robust enough to be handle any number of menus, at any depth (i.e., an
arbitary number of submenus). I'm storing each menu entry in a
multidimensional array. Since I'm getting my menu data from a MySQL
database, the simplest thing to do seemed ot be to parse out the menu
location (which looks something like "2:1:3"), then convert it into the
array index form (using the previous example, this would be [2][1][3]).
This all works fine except that when I eval the code it bombs out. I
don't even totally understand the error - can't use scalar value? What
do you mean, can't use scalar values!? I use scalar values for arrays
all the time, why can't I use one now? Furthermore, why does it work
when I copy and paste that EXACT SAME CODE into the source?

Thoughts anyone? I'm stumped. If eval doesn't work I'll have to rethink
my whole paradigm.

BTW, if you want to see the entire class file (which is still heavily
under construction), go to
http://www.*-*-*.com/
the end of the buildMenuObjArray member function (on lines 130 and 137,
but that's not necessarily helpful since phps files don't show line numbers)

<thinks for a bit>

I've been thinking about this and I realized that I could use a tree to
do what I need. It would need to support and arbitrary number of leaf
nodes off of every parent node. Before I waste my time, does anybody
know of a tree data structure written in PHP that implements this?



Sat, 21 May 2005 01:33:55 GMT  
 eval'd code is bombing... anybody know of a tree data structure I could use?

Quote:
>When I try to run eval('$this->menuArray[2][1] = new menuObj;'), I get
>the following warning:

>Warning: Cannot use a scalar value as an array in
>/home/HE/web_develop/company_home/www/cgi-bin/includes/menuCL.inc(130) :
>eval()'d code on line 1

>Any attempt to use the object $this->menuArray[2][1] fail, as it wasn't
>able to properly create the object. Here's the weird part - copying and
>pasting that code into my file lets it execute perfectly fine.

Hmmm... I couldn't test your code myself, as it's so tightly bound
to your database, but when I tried eval'ing similar code it worked
fine. One of my immediate thoughts: why are you eval'ing here at
all? Why not just do '$this->menuArray[2][1] = new menuObj;'? The
only purpose eval seems to serve here is to make it possible to
echo the code for debugging.

And why on earth are you doing separate queries for each menu item?
That seems unnecessarily slow. Why not just retrieve everything from
menuStructure at once and then parse it into a menu?

Quote:
>I've been thinking about this and I realized that I could use a tree to
>do what I need. It would need to support and arbitrary number of leaf
>nodes off of every parent node. Before I waste my time, does anybody
>know of a tree data structure written in PHP that implements this?

I haven't seen any generalized Tree classes in PHP, but they're easy
enough to implement on an as-needed basis (actually, that's basically
what you've got here with ControlMenu being a tree and menuObj being
a node). What I've generally done when I've needed a tree is to store
the data in an array and then have methods to populate it and iterate
over it as necessary. It's not necessary to use an {depth}-dimensional
array to represent the tree, either. Consider this:

array(5) {
   0=>array(2) {
      [nodeID]=>int(0)
      [children]=>array(2) {
         [0]=>int(1)
         [1]=>int(2)
      }
   1=>array(2) {
      [nodeID]=>int(1)
      [children]=>NULL
      }
   2=>array(2) {
      [nodeID]=>int(2)
      [children]=>array(1)
         [0]=>int(3)  
      }
   3=>array(2) {
      [nodeID]=>int(4)
      [children]=>array(1)
         [0]=>int(4)
      }
   4=>array(2) {
      [nodeID]=>int(4)
      [children]=>NULL
      }

Quote:
}

I hope that helps.

Dianne



Sat, 21 May 2005 03:11:37 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. using tree data structure in tcllib

2. Anybody know why I am timing out

3. Does anybody know the structure of MEM file?

4. Q: source code that uses advanced data structures

5. Does anybody know 'Enfin'?

6. Am I using EVAL correctly here?

7. Event case loses connection to data structure when data structure is modified

8. anybody knows how to verify USB link operation using Labview

9. GOBO data structure library vs other data structure libraries

10. basic tree and graph data structures

11. Efficient data structure for TREES in LISP

12. tree data structure

 

 
Powered by phpBB® Forum Software