473,659 Members | 3,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with eval()

I have this line in my code:

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

where $field is a predefined class instance, $val is a string
containing the name of an existing method within the class, and
$errDisplayArra y[$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(4 0,"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 2080
On 9 Oct 2003 14:33:46 -0700, so*****@erols.c om (Phil Powell) wrote:
I have this line in my code:

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

where $field is a predefined class instance, $val is a string
containing the name of an existing method within the class, and
$errDisplayArr ay[$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(4 0,"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, $errDisplayArra y[$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.goo gle.com...
I have this line in my code:

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


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

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

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

Jul 17 '05 #3

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

Similar topics

4
2458
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 Javascript, so I'm not really sure what needs to be removed and kept. I was trying the basic search/replaces, but always ended up with Javascript errors.
14
1344
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 function. Thanks. <script language="JavaScript"> function rankme(form) { var ans1 = eval(form.q1.value); var ans2 = eval(form.q2.value); var ans4 = eval(form.q4.value); var ans5 = eval(form.q5.value);
1
1865
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 Below is the html in the page using the <%..."value" ...%> syntax <ItemTemplate><tr><td style="background:white;font-weight:bold;font-style:italic;" width="20%"><%# DataBinder.Eval(Container, "DataItem.ReportName") %></td><td...
2
1151
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: <asp:datagrid id="clubdg" DataKeyField="UserID" runat="server" GridLines="Vertical" CellPadding="2" BorderWidth="1px" BorderColor="#CCCCFF" CssClass="txt" AutoGenerateColumns="False" OnCancelCommand="Cancel_Click"
2
4877
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" src="..\include\gen_validatorv2.js" type="text/javascript"></script> </head>
3
2855
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" RepeatDirection="Horizontal" RepeatColumns="3" CellPadding="5" CellSpacing="2" Width="100%" EnableViewState="False"> <itemtemplate> <b>
5
1405
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 It wont load it. If I set it as loader = pygame.image.load(loader) then it sets the image to the variable loader. So I'm basically trying to set a string equal to a surface variable. I dont want to have to go Sand1 = pygame.image.load("Sand1.bmp")...
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8531
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.