user3718566
user3718566

Reputation: 7

Syntax error unexpected $end

It's giving me unexpected $end but I can't find where is the problem, there's no spaces or indentation before or after EOD. I'm using eval() to do the replacing.

<?php echo <<<EOD
<?php
    if((\${$type}s = \$this->{$type}())): 
        foreach(\${$type}s as \$item):
?>

            <tr>
                <td><?php echo \$item->Name; ?></td>
                <td><?php echo Table::countRows(\$item->Name); ?></td>
                <td><?php echo \$item->Engine; ?></td>
                <td><a href="<?php echo get_url('cp/system/database/tables/view/'.\$item->Name); ?>">Show</a></td>
                <td><a href="<?php echo get_url('cp/system/database/tables/rename/'.\$item->Name); ?>">Rename</a></td>
                <td><a href="<?php echo get_url('cp/system/database/tables/delete/'.\$item->Name.'/confirm'); ?>" class="item-remove-button">Delete</a></td>
            </tr>

<?php
       endforeach; 
   endif;
?>
EOD; ?>

Upvotes: 0

Views: 92

Answers (2)

Lionel Gaillard
Lionel Gaillard

Reputation: 3023

The heredoc end tag (here EOD) must be alone on the line (with the semicolon).

Move ?> on the next line.

But, more important, what are you trying to do exactly ?

Upvotes: 0

gen_Eric
gen_Eric

Reputation: 227200

EOD; needs to be on a line by itself. You can't have anything else at all on that line.

<?php echo <<<EOD
<?php
    if((${$type}s = $this->{$type}())): 
        foreach(${$type}s as $item):
?>
EOD;
?>

            <tr>
                <td><?php echo $item->Name; ?></td>
                <td><?php echo Table::countRows($item->Name); ?></td>
                <td><?php echo $item->Engine; ?></td>
                <td><a href="<?php echo get_url('cp/system/database/tables/view/'.$item->Name); ?>">Show</a></td>
                <td><a href="<?php echo get_url('cp/system/database/tables/rename/'.$item->Name); ?>">Rename</a></td>
                <td><a href="<?php echo get_url('cp/system/database/tables/delete/'.$item->Name.'/confirm'); ?>" class="item-remove-button">Delete</a></td>
            </tr>

<?php echo <<<EOD
<?php
       endforeach; 
   endif;
?>
EOD;
?>

Docs: https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Upvotes: 3

Related Questions