PHP中abstract类中有abstract方法是否最先执行abstract方法,然后才执行其他方法?
rt
<br />
abstract class Node {<br />
private $debugMessages;<br />
<br />
public function __construct() {<br />
$this->debugMessages = array();<br />
$this->debug(__CLASS__.' constructor called.');<br />
}<br />
<br />
public function __destruct() {<br />
$this->debug(__CLASS__.' destructor called.');<br />
$this->dumpDebug();<br />
}<br />
<br />
protected function debug($msg) {<br />
$this->debugMessages[] = $msg;<br />
}<br />
<br />
private function dumpDebug() {<br />
echo implode('<br />', $this->debugMessages);<br />
}<br />
<br />
public abstract function getView();<br />
}<br />
<br />
<br />
class ForumTopic extends Node {<br />
private $debugMessages;<br />
<br />
public function __construct() {<br />
parent::__construct();<br />
$this->debug(__CLASS__.' constructor called.');<br />
}<br />
<br />
public function __destruct() {<br />
$this->debug(__CLASS__.' destructor called.');<br />
parent::__destruct();<br />
}<br />
<br />
public function getView() {<br />
return 'This is a view into '.__CLASS__.'<br />';<br />
}<br />
}<br />
<br />
$forum = new ForumTopic();<br />
echo $forum->getView();<br />
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号