Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,653 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,146 people online right now. Registration is fast and FREE... Join Now!




eval'd code is bombing out

 
Reply to this topicStart new topic

eval'd code is bombing out, Get a warning "cannot use scalar value"

jbeall
post 1 Dec, 2002 - 09:43 PM
Post #1


New D.I.C Head

*
Joined: 1 Oct, 2002
Posts: 42

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.HeraldicEnterprises.com/menuCL.phpsThe code in question is at 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)
User is offlineProfile CardPM

Go to the top of the page

jbeall
post 2 Dec, 2002 - 06:50 AM
Post #2


New D.I.C Head

*
Joined: 1 Oct, 2002
Posts: 42

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?
User is offlineProfile CardPM

Go to the top of the page

jbeall
post 2 Dec, 2002 - 07:52 AM
Post #3


New D.I.C Head

*
Joined: 1 Oct, 2002
Posts: 42

Before anybody points it out, I know I have double quotes in my post (i.e., I have eval("$this->menuArray[2][1] = new menuObj;")). I know this will cause PHP to attempt resolve $this->menuArray[2][1] to something, but in my code I don't have it double quoted, so that's not the problem. It was just a little mistake in my post. My code is clean (in that respect).
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:23AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month