All right, the parent class postparent is defined as abstract, which specifies that the subclass must re-implement the Buildhtml () method, which does not have curly braces, and if there are any content will be an error.
Now the more you see the code is not necessary to use abstract class, with inheritance is also very chicken, well, there is nothing to say as if ...
In addition i separate MySQL outside, so calling method is very troublesome
1, first instantiate readarticle
2,mysql query, parameters from Readarticle::getsql ();
3, return the MySQL result resource to Readarticle::fetchresult ($result);
4,readarticle::buildhtml (); return HTML
If it's a list loop output, repeat the call 3 and 4.
Copy the Code code as follows:
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 '}
{$this->fetchresult[' author '}At
{$this->timeago}
{$this->fetchresult[' text ']}
Eof
}
}
The above describes the abstract class of PHP abstract class simple application, including the content of the abstract class, I hope that the PHP tutorial interested in a friend to help.