I have a class named Display which extends class Layout, which extends class DOMDocument. I get: Fatal error: Call to a member function loadHTMLFile() on a non-object. Code as follows:
In index.php :
$dom = new Display();
$dom->displayData();
In Display.php :
class Display extends Layout {
public function displayData(){
$dom = parent::__construct();
$dom->loadHTMLfile("afile.html");
echo $dom->saveHTML();
}
}
My question is: When I call parent::__construct() , isn’t this the same as using “new DOMDocument“, since the Display class extends Layout and DOMDocument?Thanks
If you have the
loadHTMLfilefunction in your parent class, the subclass will inherit it. So you should be able to do: