473,385 Members | 1,341 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.

Problems Using Eval

I'm fooling around with using Eval and trying to manipulate a few things. I
ran into a couple of weird results. First of all, in one place I used the
following code:

$filestring = str_replace("<?", "\n<?\n", $filestring);
$filestring = str_replace("?>", "\n?>\n", $filestring);

Not a huge thing, just making things easier to read for me. But doing this
gives me an error, even when I comment those lines out. I have to remove
them completely, it seems to be interpreting the ?and <? strangely even
when they're in quotes or commented out. Why is that?

Second thing, I'm having trouble getting eval to work with some of the code,
and I have no idea why. It grabs the code to eval from other files, and I
can't see any reason why it shouldn't work. This is the error message I'm
getting:

Parse error: parse error, unexpected $ in
/homepages/htdocs/parrot0123/tester.php(498) : eval()'d code on line 44

I exploded the eval code and print_r'd the results, and this is what I got:

Array
(
[0] =global $monthname;
[1] =global $config;
[2] =$now = time();
[3] =$today = getdate($now);
[4] =$curmonth = $today['mon'];
[5] =$curyear = $today['year'];
[6] =// Determine whether it's a leap year
[7] =$leapyear = 0;
[8] =$remainder = $curyear % 400;
[9] =if(!$remainder)
[10] ={
[11] = $leapyear = 1;
[12] =}
[13] =else
[14] ={
[15] = $remainder = $curyear % 100;
[16] = if ($remainder)
[17] = {
[18] = $remainder = $curyear % 4;
[19] = if (!$remainder)
[20] = {
[21] = $leapyear = 1;
[22] = }
[23] = }
[24] =}
[25] =// Set the number of days per month
[26] =$mdays[1] = 31;
[27] =$mdays[2] = 28 + $leapyear;
[28] =$mdays[3] = 31;
[29] =$mdays[4] = 30;
[30] =$mdays[5] = 31;
[31] =$mdays[6] = 30;
[32] =$mdays[7] = 31;
[33] =$mdays[8] = 31;
[34] =$mdays[9] = 30;
[35] =$mdays[10] = 31;
[36] =$mdays[11] = 30;
[37] =$mdays[12] = 31;
[38] =// Calculate the day of the week that the first day of this
months falls on
[39] =$_POST['nowmonth'] = mktime(0, 0, 0, $curmonth, 1, $curyear);
[40] =$cmstamp = $_POST['nowmonth'];
[41] =$datevals = getdate($ts);
)There's no line 44, what could the problem possibly be?
Sep 26 '07 #1
5 1948
Smiley wrote:
I'm fooling around with using Eval and trying to manipulate a few things. I
ran into a couple of weird results. First of all, in one place I used the
following code:

$filestring = str_replace("<?", "\n<?\n", $filestring);
$filestring = str_replace("?>", "\n?>\n", $filestring);

Not a huge thing, just making things easier to read for me. But doing this
gives me an error, even when I comment those lines out. I have to remove
them completely, it seems to be interpreting the ?and <? strangely even
when they're in quotes or commented out. Why is that?
Hi Smiley,

I tested it, and that is NOT happening here (PHP5.2).
What version are you on?

Most probably PHP sees them as begin and end of script.
Maybe it helps to escape them in your case.
Like this:
$filestring = str_replace("\<\?", "\n\<\?\n", $filestring);

Or are you maybe using this code TOO in the wretched eval way you
describe below?

>
Second thing, I'm having trouble getting eval to work with some of the code,
and I have no idea why. It grabs the code to eval from other files, and I
can't see any reason why it shouldn't work. This is the error message I'm
getting:
Why are you using eval?
>
Parse error: parse error, unexpected $ in
/homepages/htdocs/parrot0123/tester.php(498) : eval()'d code on line 44

I exploded the eval code and print_r'd the results, and this is what I got:

Array
(
[0] =global $monthname;
[1] =global $config;
[2] =$now = time();
[3] =$today = getdate($now);
[4] =$curmonth = $today['mon'];
[5] =$curyear = $today['year'];
[6] =// Determine whether it's a leap year
[7] =$leapyear = 0;
[8] =$remainder = $curyear % 400;
[9] =if(!$remainder)
[10] ={
[11] = $leapyear = 1;
[12] =}
[13] =else
[14] ={
[15] = $remainder = $curyear % 100;
[16] = if ($remainder)
[17] = {
[18] = $remainder = $curyear % 4;
[19] = if (!$remainder)
[20] = {
[21] = $leapyear = 1;
[22] = }
[23] = }
[24] =}
[25] =// Set the number of days per month
[26] =$mdays[1] = 31;
[27] =$mdays[2] = 28 + $leapyear;
[28] =$mdays[3] = 31;
[29] =$mdays[4] = 30;
[30] =$mdays[5] = 31;
[31] =$mdays[6] = 30;
[32] =$mdays[7] = 31;
[33] =$mdays[8] = 31;
[34] =$mdays[9] = 30;
[35] =$mdays[10] = 31;
[36] =$mdays[11] = 30;
[37] =$mdays[12] = 31;
[38] =// Calculate the day of the week that the first day of this
months falls on
[39] =$_POST['nowmonth'] = mktime(0, 0, 0, $curmonth, 1, $curyear);
[40] =$cmstamp = $_POST['nowmonth'];
[41] =$datevals = getdate($ts);
)There's no line 44, what could the problem possibly be?

I have no clue what you are trying to accomplish with this strange
approach, but I think you better start redesinging your app right away.
Avoid eval. It is bugprone, opens up securityholes, and is extremely
hard to debug.
Simply don't.

Sorry I cannot be of more help.
I think you'll find most people in here won't encourage this approach.

Regards,
Erwin Moller
Sep 26 '07 #2
I have no clue what you are trying to accomplish with this strange
approach, but I think you better start redesinging your app right away.
Avoid eval. It is bugprone, opens up securityholes, and is extremely
hard to debug.
Simply don't.
That's what I thought as well. Why not simply include that file? I
mean, it would surely give you less headaches...

Sep 26 '07 #3
"RageARC" <ra*****@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
>
That's what I thought as well. Why not simply include that file? I
mean, it would surely give you less headaches...
What I'm trying to do is figure out a way to work in simplified coding
statements for an end user who uses a system so that they can have a greater
deal of control without needing to know PHP code. The simplified code is
interpreted, but I also wanted the ability for users to put in their own PHP
code so I'm using eval to those parts of it.
Sep 26 '07 #4
On Wed, 26 Sep 2007 10:11:45 +0200, Smiley <no****@noplace.comwrote:
I'm fooling around with using Eval and trying to manipulate a few
things. I
ran into a couple of weird results. First of all, in one place I used
the
following code:

$filestring = str_replace("<?", "\n<?\n", $filestring);
$filestring = str_replace("?>", "\n?>\n", $filestring);
Works here...
Second thing, I'm having trouble getting eval to work with some of the
code,
and I have no idea why. It grabs the code to eval from other files, and
I
can't see any reason why it shouldn't work. This is the error message
I'm
getting:

Parse error: parse error, unexpected $ in
/homepages/htdocs/parrot0123/tester.php(498) : eval()'d code on line 44

I exploded the eval code
Why? The raw data would tell you more.... And there's no possibly removing
of 'empty' elements. Also be very aware of HTML rendering: look at the
source of the output, not how it displays in a browser.

and print_r'd the results, and this is what I
got:

Array
(
<SNIP>

Can't say I see any problem so quickly.
--
Rik Wasmus
Sep 26 '07 #5
Smiley wrote:
"RageARC" <ra*****@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
>That's what I thought as well. Why not simply include that file? I
mean, it would surely give you less headaches...

What I'm trying to do is figure out a way to work in simplified coding
statements for an end user who uses a system so that they can have a greater
deal of control without needing to know PHP code. The simplified code is
interpreted, but I also wanted the ability for users to put in their own PHP
code so I'm using eval to those parts of it.
Hi Smiley,

I am aware of the fact it must be irritating to receive responses like
this, but we advise this because we want to help.

If your goal is to simplify coding statements, I would start using OOP
instead.

So instead of building an array with pieces of code on each line, build
an object that has methods that do the same.

You'll end up with code like:
$smileyObj->resetCalc();
$smileyObj->add(12);
$smileyObj->add(34.5);
$smileyObj->add(1.123);
echo $smileyObj->calculateAverage();

One (very good) reason OOP exists/is popular is the fact you can hide
complexity behind a simple method.
Allthough I don't want to say my example (average calculation) has
anything to do with complexity. ;-)

Regards,
Erwin Moller
Sep 27 '07 #6

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

Similar topics

0
by: Robert Brewer | last post by:
Hello, I realize I'm a bit over my head, here, but I'm trying to pull waypoint data from a Garmin eTrex Legend, and having mixed success. On a Win98 box last night, I was able to connect and...
12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
8
by: Eclectic | last post by:
I have a couple of layers that are hidden. When an image is moused over, I want to show the appropriate layer, then hide it on mouseOut. The problem is, I get an error telling me...
12
by: Scott Mitchell | last post by:
I am using the onbeforeunload client-side event to prompt a user when leaving a page after they have made changes, as discussed in this article: Using ASP.NET to Prompt a User to Save When Leaving...
0
by: Gastin | last post by:
I am digesting a web serivce from Amazon.Com. I have the following class which was autogenerated by VS.NET when I created a Web Reference to...
0
by: dfgasner | last post by:
Sry I'm very new to VB.net and am trying to create a shopping cart by way of a book that teaches you VB.net along the way. Unfortunatly I'm stuck cuz I ran into this error and I can't seem to find...
5
by: Chris Lieb | last post by:
I am trying to add an event listener to the keyup event for some text inputs that I am creating dynamically. I have no problems getting it to work in Firefox, but IE just ignores them. I have...
15
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
1
by: mister-Ed | last post by:
I am displaying subcategories in my datalist, and now I have a bizarre thing happen when I add a new subcategory record in my sql database, the new subcategory link does not click into the next...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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...

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.