extends in action : extends Class PHP

<?php
class Checkout {
    final function totalize() {
        // calculate bill
    }
}

class IllegalCheckout extends Checkout {
    final function totalize() {
        // change bill calculation
    }
}

$checkout = new Checkout();

?>


           
       

extends and implement : Inheritance Class PHP

<?php

   class Employee {
      private $name;

      function setName($name) {
         if ($name == "") 
           echo "Name cannot be blank!";
         else 
           $this->name = $name;
      }

      function getName() {
         return "My name is ".$this->name."<br />";
      }

   }
   interface MyInterface
   {
      function account();
      function doc();
   }

   class Executive extends Employee implements MyInterface
   {
      private $totalStockOptions;

      function account()
      {
         echo "account";
      }

      function doc()
      {
         echo "doc";
      }
   }

   class Assistant extends Employee implements MyInterface
   {
      function takeMemo() {
         echo "memo";
      }

      function account(){
         echo "memo";
      }

      function doc(){
         echo "Start small fire in the trash can.";
      }
   }


?>

           
       

extends Exception to create your own exception : Exception Statement PHP

 
<?php

class MyException extends Exception { 
    function __construct($language,$errorcode) { 
        $this->language = $language;
        $this->errorcode = $errorcode;
    } 

    function getMessageMap() {
        $errors = file("errors/".$this->language.".txt");
        foreach($errors as $error) {
             list($key,$value) = explode(",",$error,2);
             $errorArray[$key] = $value;
        }
        return $errorArray[$this->errorcode];
    }  
}

try {
    throw new MyException("english",4);
}
catch (MyException $e) {
    echo $e->getMessageMap();
}

?>
  
  

explode.php : explode Data Structure PHP

 
<?php
$summary = <<< summary
line 1
line 2
<a href="http://www.php.net">PHP 5</a>
summary;
$words = sizeof(explode(' ',strip_tags($summary)));
echo "Total words in summary: $words";
?>