解析错误:语法错误,意外&#39 ;;',期待标识符(T_STRING)或变量(T_VARIABLE)

时间:2014-04-06 17:54:14

标签: php

我的代码有问题。 (我找了一些解决方案,但我没有找到任何东西,所以这就是我发布主题的原因)

错误:

Parse error: syntax error, unexpected ';', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in XXXXXX on line 13

第13行:

echo $view->;htmlError();

我的代码:

<?php
require_once 'classes/View.php';

echo DB_HOSTNAME; //output: hostname

$view = new View();

if ($htmlString = $view->tableThreads()) {
    echo $htmlString;
} else {
    echo $view->;htmlError();
}

echo $view->buttonPostThread();
?>

View.php

// we need the class db to make an object
require_once 'database.php';

//we'll also need the recaptcha helper later
require_once 'helpers/recaptcha.php';

class View{

    private $db;

    function __construct()
    {
        $this->db = new Database();
    }

    function tableThreads()
    {
        $content = "";

        if (($threads = $this->db->getThreads()) && mysql_num_rows($threads) > 0) {
             $content .= '<h1>Threads</h1>';
             $content .= '<table border="0" width="" id="posts_list">';
             $content .= '<tr>';
             $content .= '<th class="title">Title</td>';
             $content .= '<th>Date</td>';
             $content .= '<th>User</td>';
             $content .= '</tr>';

            while ($row = mysql_fetch_assoc($threads)) {
                $content .= '<tr class="thread">';
                $content .= '<td class="title">';
                $content .= '<a href="view_thread.php?permalink=';
                $content .= htmlspecialchars($row['permalink']) . '">'.$row['title'].'</a>';
                $content .= '</td>';
                $content .= '<td class="date">'.htmlspecialchars($row['date']).'</td>';
                $content .= '<td class="author">'.htmlspecialchars($row['author']).'</td>';
                $content .= '</tr>';
            }
            $content .= '</table>';
            return $content;
        } else {
            return false;
        }
    }

private function composeTable($post, $firstPost, $numRows)
{
    $htmlTable = "";

    if ($firstPost)
        $htmlTable .= '<h1>'.htmlspecialchars($post['title']).'</h1>';

    $htmlTable .= '<table border="0" width="895">';
    $htmlTable .= ' <tr>';
    $htmlTable .= '     <th>Message</th>';
    $htmlTable .= '     <th>Date</th>';
    $htmlTable .= '     <th>Author</th>';
    $htmlTable .= ' </tr>';
    $htmlTable .= ' <tr>';
    $htmlTable .= '     <td class="title">'.htmlspecialchars($post['content']).'</td>';
    $htmlTable .= '     <td class="date">'.htmlspecialchars($post['date']).'</td>';
    $htmlTable .= '     <td class="author">'.htmlspecialchars($post['author']).'</td>';
    $htmlTable .= ' </tr>';
    $htmlTable .= '</table>';
    if ($firstPost && $numRows &gt; 1)
        $htmlTable .= '<h1>Responses</h1>';

    return $htmlTable;
}

function tableThreadContent($permalink)
{
    $content = "";

    if ($posts = $this->db->getContentThread($permalink)) {
        $num_rows = mysql_num_rows($posts);
        if ($num_rows > 0) {
            while($row = mysql_fetch_assoc($posts))
                $content .= $this->composeTable($row,
                    is_null($row['permalink_parent']),
                    $num_rows);
        }
        return $content;
    } else {
        return false;  //database error
    }
}

[/html]

<p>The second method goes around all the posts in a thread and composes the HTML with the first one (composeTable). </p>

<p>The method composeTable is private because we'll only call it from the tableThreadContent method in the same class and its functionality is only useful inside this class. In the future if we want to make a class that extends this one and uses that method all we need to do is change private for protected.</p>

<p>Now let's think about what happens if we don't have a single thread. Apart from being very sad it could be a problem if we don't show a warning message. This is a very simple method to do that:</p>

function htmlError($from_view_thread = false)
{
    if ($from_view_thread) {
        //From view_thread.php
        $html = '<p class="error">There is no thread with this title. Sorry! ';
        $html .= 'You can go back to <a href="index.php">the main page</a>.</p>';
    }else{
        // From index.php
        $html = '<p class="error">There aren\'t any threads. Sorry! </p>';
    }
    return $html;
}

function buttonPostThread()
{
    return '<div class="newThread">'
          .'<a href="post_message.php">Create a new thread</a>'
          .'</div>';
}

3 个答案:

答案 0 :(得分:2)

您需要更正这一行:

echo $view->;htmlError();

要:

echo $view->htmlError();

如需休息,请检查您的密码。

答案 1 :(得分:1)

您必须将第13行替换为:

echo $view->html Error();

因为你有一个额外的“;”

答案 2 :(得分:0)

在PHP 5.5及以上版本中

$this->middlewares[$k] = Instance::ensure($middleware, Middleware::class);

并在下面的PHP 5.5中

$this->middlewares[$k] = Instance::ensure($middleware, 'Middleware');

PHP 5.4不支持Class :: class