Using Type Hinting with Interfaces : Interface « Class « PHP






Using Type Hinting with Interfaces

 
<?php
     interface printable {
          public function printme();
     }

     abstract class Number {
          private $value;
          abstract public function value();
          public function reset() {
               $this->value = NULL;
          }
     }

     class Integer extends Number implements printable {
          private $value;
          function __construct($value) {
               $this->value = $value;
          }
          public function getValue() {
               return (int)$this->value;
          }
          public function printme() {
               echo (int)$this->value;
          }
     }

     function printNumber(printable $myObject) {
          $myObject->printme();
     }
     $inst = new Integer(10);
     printNumber($inst);
?>
  
  








Related examples in the same category

1.Implement an interface
2.Different class implements one interface
3.A Sample Interface
4.Implementing Multiple Interfaces
5.Defining an interface
6.Defining and Using an Interface