Re: Problems Using Eval



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
.



Relevant Pages

  • Re: c++builderx
    ... >> I got a strange thing. ... >> In solaris,gzip return error message. ... >> In windows winzip decompress the file successfully. ... >> Anyone knows reason? ...
    (comp.unix.programmer)
  • Re: Very strange: program validates differently in 98 and XP
    ... informal computer advisor) so strange to me that I hardly know how to ... Ken Blake - Microsoft MVP Windows: ... either of these brings up an error message "Must be "X" or ... attempting to re-install the program brings up some sort of progress ...
    (microsoft.public.windowsxp.help_and_support)
  • List Index out of Bounds (9) when loading form ??
    ... Two days ago - when I open the main form - I get the error message "List ... What is also strange is that I can open the form on its own - outside ... List index out of bounds. ... 4002fd69 rtl60.bpl Classes GlobalFixupReferences ...
    (borland.public.delphi.ide)
  • Windows XP problem (potential virus)
    ... My Win XP system had a virus and was doing 2 strange ... it was displaying an error message regarding ... the startbar and the desktop icons and then stop and go to ...
    (microsoft.public.windowsxp.security_admin)
  • Re: A software issue
    ... It did NOT give any error message and exactly as you guessed, strangely, just sat there and did nothing. ... Now I'm installing it again and here's the procedure: ... The icon appears on the desktop AND when I double-click it, ... Strange! ...
    (Ubuntu)