Hello php gurus!
I'm trying to make a simple template generator that's going to be used with XML files.
In doing so, I've laid out a simple structure, but before I can even get to work on the template generator,
I've run into some problems with inheritance problems.
Basic structure is
interface c {}
abstract class a {}
class b extends a implements c {}
$d = new b();
which works fine.
But the same structure with my code doesn't work.
Here's the simplified version of my code
interface class
<?php
interface Core
{
function register($obj);
function unregister($obj);
}
?>
abstract class
<?php
abstract class Engine
{
// ?return [boolean]
abstract protected function hireEngineer();
// ?return [boolean]
abstract protected function fireEngineer();
// ?return [int]
protected function attach($part, $type)
{
if(DEBUG)
printf("#DEBUG# attaching engine parts of ".var_dump($refPart));
if(!is_object($part))
exit();
$this->coreID = $type."_".get_class($part);
if(!$this->registry[$this->coreID] = $part)
exit();
$this->clearID();
return count($this->registry);
}
// ?return [boolean]
protected function detach($part, $type)
{
$this->coreID = $type."_".get_class($part);
if(DEBUG)
printf("#DEBUG# detaching engine parts of ".var_dump($part));
if($key = array_search($this->coreID, $this->registry))
{
unset($this->registry[$key]);
}
$this->clearID();
return true;
}
// ?return [void]
private function clearID()
{
$this->coreID = "";
}
///////////////////////////////////////////////////////////////////
protected $registry;
protected $coreID;
}
?>
And the class that inherits the abstract class
<?php
final class Input extends Engine implements Core
{
public function __construct()
{
parent::$registry = array();
parent::$coreID = null;
}
// ?return [boolean]
public function hireEngineer()
{
; // do nothing for now
}
// ?return [boolean]
public function fireEngineer()
{
; // do nothing for now
}
// ?return [int]
public function register($obj)
{
return $this->attach($obj, "Input");
}
public function unregister($obj)
{
return $this->detach($obj, "Input");
}
}
?>
I get the "Cannot instantiate an abstract class Input".
I just can't figure out why the compiler thinks Input is an abstract class.
I'd appreciate if anyone could help.
EDIT:
What is the order of object creation in inheritance in php?
I can't help but feeling this error is somewhat similar to passing this to the base class in C++...
EDIT: fixed some typos