Jump to content

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.

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.