Advertisement
sri211500

Untitled

Feb 25th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php
  2.  
  3. //Declare the interface 'iTemplate'
  4. interface iTemplate
  5. {
  6. public function setVariable($name, $var);
  7. public function getHtm($template);
  8. }
  9.  
  10. //Implement the interface
  11. //This will work
  12. class Template Implements iTemplate
  13. {
  14. private $vars = array();
  15.  
  16. public function setVariable($namae, $var)
  17. {
  18. $this->vars[$name] =$var;
  19. }
  20. public function getHtm($template)
  21. {
  22. foreach($this->vars as $name => $value){
  23. $Template = str_replace('['. $name . ']', $value, $Template);
  24. }
  25.  
  26. return $Template;
  27. }
  28. }
  29.  
  30. //This will not work
  31. //Fatal error: Class BadTemplate contains 1 abstrack methods
  32. //and must therefore be declared abstract(iTemplate::getHtm)
  33. class BadTemplat Implements iTemplate
  34. {
  35. private $vars = array();
  36.  
  37. public funcation setVariable($name, $var)
  38. {
  39. $this->vars[$name] = $var;
  40. }
  41. }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement