I am wondering how to make subclasses implement this interface method.
Let's say I have the following classes:
interface Serializable { public function __toString(); } abstract class Tag // Any HTML or XML tag or whatever like <div>, <p>, <chucknorris>, etc { protected $attributes = array(); public function __get($memberName) { return $this->attributes[$member]; } public function __set($memberName, $value) { $this->attributes[$memberName] = $value; } public function __construct() { } public function __destruct() { } }
I would like to force any subclass of the Tag class to implement the Serializable interface. For example, if I am a “paragraph class”, it will look like this:
class Paragraph extends Tag implements View { public function __toString() { print '<p'; foreach($this->attributes as $attribute => $value) print ' '.$attribute.'="'.$value.'"'; print '>';
How to force a developer to force his "Paragraph" class to implement methods from the "Serializable" interface?
Thanks for taking the time to read.
source share