freelance programmers outsource from india freelance programmers  chennai india programmers freelance programmers  freelance php coder freelance outsource scripts freelance programmers programming complicated perl patterns freelance programmers php module installation freelance programmers
freelance programmers  outsource from india freelance programmers  perl installation and configuration freelance programmers  php installation linux system freelance programmers administration US$15,US$19,US$11,US$10 cheap programmer
india outsource outsource india chennai india programmers php perl mysql freelance freelance programmer
SHOWCASE of php and perl scripts CONTACT US for php custom perl scripts
HOME
 

Object Interfaces

Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.

Interfaces are defined using the interface keyword, in the same way as a standard class, but without any of the methods having their contents defined. Classes which implement an interface should do so using the implements keyword, and must have definitions for all the methods listed in the interface. Classes may implement more than one interface if desired by listing each interface split by a comma.

All methods declared in an interface must be public, this is the nature of an interface.

Stating that a class implements an interface, and then not implementing all the methods in the interface will result in a fatal error telling you which methods have not been implemented.

Example 19-17. Interface example

<?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 error: 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;
    }
}

?>

Copyright © 1997 - 2007 by the PHP Documentation Group. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later. A copy of the Open Publication License is distributed with this manual, the latest version is presently available at http://www.opencontent.org/openpub/. Please see full copyright text at http://www.php.net/manual/en/copyright.php Original version of the above documentation is available at http://www.php.net/manual/en/



  1. Please click on Dedicated servers review directory ppc website
  2. Please Also click on our Web developers Showcase



Web design and Programming Copyright @ Chrisranjana.com 1999-2007. Website designed and Webdevelopers and Website programmed by Web developers and Software programmers. We do excellent software development in asp and .net c# csharp also