Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Created November 9, 2016 18:48
Show Gist options
  • Select an option

  • Save gorkamu/7fb35daa09e7562ed31e39c8b1d7968a to your computer and use it in GitHub Desktop.

Select an option

Save gorkamu/7fb35daa09e7562ed31e39c8b1d7968a to your computer and use it in GitHub Desktop.
Ejemplo de interface
<?php
interface iTemplate
{
public function setVariable($name, $var);
public function getHtml($template);
}
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;
}
}
// Ésto no funcionará
// Error fatal: La Clase BadTemplate contiene un método abstracto
// y por lo tanto debe declararse como abstracta (iTemplate::getHtml)
class BadTemplate implements iTemplate
{
private $vars = array();
public function setVariable($name, $var) {
$this->vars[$name] = $var;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment