Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Declare the interface 'iTemplate'
- interface iTemplate
- {
- public function setVariable($name, $var);
- public function getHtml($template);
- }
- /**
- Implement the interface
- This will work
- */
- class Template Implements iTemplate
- {
- private $vars = array();
- public function setVariable($name, $var)
- {
- $this-vars[$name] = $var;
- }
- public function getHtml($template)
- {
- foreach ($this->vars as $name => $value) {
- $template = str_replace('{'.$name.'}', $value, $template);
- }
- return $template;
- }
- }
- /**
- This will not work
- Fatal eroor: Class BadTemplate contains 1 abstract methods
- and must therefore be declared abstract (iTemplate::getHtml)
- */
- class BadTemplate Implements iTemplate
- {
- private $vars = array();
- public function setVariable($name, $var)
- {
- $this->vars[$name] = $var;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment