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

Help with eval()

I have this line in my code:

eval('$field->' . $val . '(' . $max . ',' . $errDisplayArray[$key] .
');');

where $field is a predefined class instance, $val is a string
containing the name of an existing method within the class, and
$errDisplayArray[$key] will be an array element containing text that
goes appropriately into the class method whose name is in $val.

Whenever I run this I get a parse error, however, upon using a die()
statement instead of eval it configures as so (and works!):

$field->setMaxLength(40,"The last name cannot be more than 40
characters");

when I insert this line verbatim into my code I receive no breakage of
any kind upon that line. I have read the eval() statement all over
php.net, phpbuilder, phpfreaks and zend and I can't see what I'm doing
wrong. Could someone clarify it for me?

Thanx
Phil
Jul 17 '05 #1
2 2068
On 9 Oct 2003 14:33:46 -0700, so*****@erols.com (Phil Powell) wrote:
I have this line in my code:

eval('$field->' . $val . '(' . $max . ',' . $errDisplayArray[$key] .
');');

where $field is a predefined class instance, $val is a string
containing the name of an existing method within the class, and
$errDisplayArray[$key] will be an array element containing text that
goes appropriately into the class method whose name is in $val.
First question would be: what are the actual values of each of those
variables? Echo them out and post them please.

Then construct the string you're going to eval() and put it in another
variable; echo that out, to make sure it's all exactly as you wanted.
Whenever I run this I get a parse error, however, upon using a die()
statement instead of eval it configures as so (and works!):

$field->setMaxLength(40,"The last name cannot be more than 40
characters");
Ah, you're saying that's the output from die()? OK.

So exactly what sort of parse error do you get from it?
when I insert this line verbatim into my code I receive no breakage of
any kind upon that line. I have read the eval() statement all over
php.net, phpbuilder, phpfreaks and zend and I can't see what I'm doing
wrong. Could someone clarify it for me?


Well - first I'd wonder if you really need the dangerous eval() at all. What
about call_user_func?

call_user_func(array(&$field, $val), $max, $errDisplayArray[$key]);
http://uk2.php.net/call_user_func

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2

"Phil Powell" <so*****@erols.com> wrote in message
news:1c**************************@posting.google.c om...
I have this line in my code:

eval('$field->' . $val . '(' . $max . ',' . $errDisplayArray[$key] .
');');


Actually, you don't have to use eval() in this case. See the example below:

class MyClass {
function echoInput($input) {
echo $input;
}
}

$myclass = new MyClass;
$method = "echoInput";
$myclass->$method('Hello World');
JW

Jul 17 '05 #3

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

Similar topics

4
by: fartsniff | last post by:
Hello all. Can someone help out ? I found this PHP code that works just fine, however, I am trying to put it back into its original Javascript form. I am still learning the syntax, etc. for...
14
by: KL | last post by:
I am writing this function and I think I messed up something cause it won't work. Can someone help me see what I am doing wrong?? I have included the function and the part where I call the...
1
by: Donnie | last post by:
Hello I'm receiving the following error message when I try to view an aspx page in Design view "Could not open in Design View. Quote values differently inside a '<%... "value" ... %>' block ...
2
by: I am Sam | last post by:
Ok I set up a button column to delete an individual record. Nothing happens when I test it. Someone please help understand why. Below is the associated coding: DataGrid control: ...
2
by: this one | last post by:
I have the following code <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"...
3
by: vishnu | last post by:
Hi, I have a link that is coming from the database.Now if the link is empty i dont want to display in datalist .How can i do that? <td><asp:DataList id="DataList1" Runat="server"...
5
by: katie smith | last post by:
Here is the program I just started, The problem i am having is I'm trying to get it to load the image file Sand1 with eval(loader) = pygame.image.load(loader) because Loader is euqual to "Sand1" but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.