Jump to content

[SOLVED] eval() with heredoc not working


inactive

Recommended Posts

Hey guys,

I'm running eval() on a var containing some php code (should be OK, right?).

 

Well it works, but as soon as I add some heredoc code (i.e. <<<EOF), it has a fit.

 

Here is the code from the parent script:

<?php

$handle = @fopen("foo.inc", "r");
if ($handle) {
$buffer = '';
    while (!feof($handle)) {
        $buffer .= fgets($handle, 4096);
    }
    fclose($handle);

eval(buffer);

} else {
echo 'shit! something went wrong';
}

?>

 

And foo.inc is:

$var1 	= 'test text';
$var2	= 'some more test text';

$arr1	= array('alpha','beta','charlie');

$var_heredoc_1 = <<<ENDBODY
foo
bar
foobar
ENDBODY;

 

And for my trouble I get:

Parse error: syntax error, unexpected $end in index.php(11) : eval()'d code on line 10

 

If I remove the heredoc part, it works as expected (note that the code above has been simplified a fair bit).

 

Any ideas? I'm sure the syntax in foo.inc is correct (as I renamed it foo.php, and put <?php ?> around, and it worked correctly.

 

Is there limitations on what can and cannot be aval()'ed?

 

Any help would be much appreciated.

 

Thanks guys.

Link to comment
Share on other sites

  • 6 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.