Jump to content

[SOLVED] Parse error on a function?


Mr Chris

Recommended Posts

Hello,

 

I'm trying to put together a function but am getting the message:

 

Parse error: syntax error, unexpected $end   at the end of the function.

 

I know this normally happens when the { and } don't match up, but unless i'm going bonkers they do?

 

Any ideas?

 

Thanks

 

 

<? 
function FuncName() { 
$total = 0; 
$output = '<form action="" method="post"> 
   <input type="hidden" name="aaa" value="bbb"> 
   <input type="hidden" name="fff" value="1"> 
   <input type="hidden" name="ddd" value="666666k">'; 

            foreach ($this->Cart as $ProductID => $Qty){ 
                $result = $Database->query('SELECT * FROM books WHERE id = '.$ProductID); 
                $row = $result->fetch(); 
                $price = sprintf('£%.2f', $row['price']); 
                $rowTotal = sprintf('£%.2f', $row['price'] * $Qty); 
                $total += $row['price'] * $Qty; 
                $output .= <<<ROW
                  <input type="hidden" name="one_{$ProductID}" value="{$description}"> 
                  <input type="hidden" name="two_{$ProductID}" value="{$rowTotal}"> 
                  <input type="hidden" name="three_{$ProductID}" value="{$Qty}"> 
            ROW; 
            } 
            $total = sprintf('£%.2f', $total); 
            $output .= <<<END
            <input type="submit" value="Submit"> 
</form> 

END; 
            return $output; 
        } 
    } 
?>

Link to comment
https://forums.phpfreaks.com/topic/162059-solved-parse-error-on-a-function/
Share on other sites

IIRC,

            ROW;

should be

ROW;

i.e. the ROW; to terminate the heredoc must be the very first characters in the line, no white space or anything is permitted.

 

edit - added warning quoted from the PHP manual

It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline.

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.