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
https://forums.phpfreaks.com/topic/121169-solved-eval-with-heredoc-not-working/
Share on other sites

  • 6 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.