时间:2021-07-01 10:21:17 帮助过:23人阅读
abstract class postParent
{
protected $querySQL;
public $fetchResult;
public $timeAgo; // eg : 2 days ago
abstract protected function buildHTML();
public function getSQL()
{
return $this->querySQL;
}
public function fetchResult( $result )
{
$this->fetchResult = mysql_fetch_assoc( $result );
}
public function error()
{}
}
class readArticle extends postParent
{
public function __construct( $id )
{
$this->querySQL =<<SELECT title, author, text, unixtime FROM post
WHERE id = $id ORDER BY unixtime DESC;
eof;
}
public function buildHTML()
{
return <<
fetchResult['id']}"
class="post-title-a" > {$this->fetchResult['title']}
at
{$this->fetchResult['text']}
eof;
}
}
http://www.bkjia.com/PHPjc/324297.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324297.htmlTechArticleAll right, 父类postParent定义为抽象,规定子类必须重新实现 buildHTML()方法,这个方法并没有花括号,如果有不管有没有内容都会报错的。 现在...