downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Interfaces> <Static Schlüsselwort
Last updated: Fri, 30 Oct 2009

view this page in

Klassenabstraktion

PHP 5 führt abstrakte Klassen und Methoden ein. Es ist nicht erlaubt, eine Instanz einer Klasse zu erzeugen, die abstrakt definiert wurde. Jede Klasse, die wenigstens eine abstrakte Methode enthält, muss ebenso abstrakt sein. Abstrakt definierte Methoden deklarieren einfach die Signatur der Methode, sie dürfen nicht die Implementierung definieren.

Wenn eine abstrakte Klasse abgeleitet wird, müssen alle in der Deklaration der Vaterklasse abstrakt bezeichneten Methoden durch das Kind definiert werden. Zusätzlich müssen diese Methoden mit der selben (oder einer weniger einschränkenden) Sichtbarkeit definiert werden. Wenn die abstrakte Methode zum Beispiel als protected definiert ist, muss die Funktionsimplementierung entweder als protected oder public, aber nicht private, definiert sein.

Beispiel #1 Beispiel für abstrakte Klasse

<?php
abstract class AbstractClass
{
    
// Die abgeleitete Klasse zwingen, diese Methoden zu definieren
    
abstract protected function getValue();
    abstract protected function 
prefixValue($prefix);

    
// Gemeinsame Methode
    
public function printOut() {
        print 
$this->getValue() . "\n";
    }
}

class 
ConcreteClass1 extends AbstractClass
{
    protected function 
getValue() {
        return 
"ConcreteClass1";
    }

    public function 
prefixValue($prefix) {
        return 
"{$prefix}ConcreteClass1";
    }
}

class 
ConcreteClass2 extends AbstractClass
{
    public function 
getValue() {
        return 
"ConcreteClass2";
    }
    
    public function 
prefixValue($prefix) {
        return 
"{$prefix}ConcreteClass2";
    }
}

$class1 = new ConcreteClass1;
$class1->printOut();
echo 
$class1->prefixValue('FOO_') ."\n";

$class2 = new ConcreteClass2;
$class2->printOut();
echo 
$class2->prefixValue('FOO_') ."\n";
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

ConcreteClass1
FOO_ConcreteClass1
ConcreteClass2
FOO_ConcreteClass2

Bestehender Code, der keine benutzerdefinierten Klassen oder Funktionen mit dem Namen 'abstract' besitzt, sollte ohne Änderungen lauffähig sein.



Interfaces> <Static Schlüsselwort
Last updated: Fri, 30 Oct 2009
 
add a note add a note User Contributed Notes
Klassenabstraktion
m.hofrichter
26-Oct-2009 11:10
I discovered that when using the @abstract tag from php-doc  my ide
will give the option to implement all abstract methods automaticly.
many developers know this feature from Java ide's like netbeans,intelli-j or eclipse.

regards

example of php-doc @abstract tag ...

<?php
/**
 * Abstract class PageController
 *
 * @see PageController:exec()
 * @see PageController::doGET()
 * @see PageController::doPost()
 *
 * @abstract
 * @author hofrichter
 */
abstract class MyController {

    abstract protected function
doGET();

    abstract protected function
doPOST();

    abstract public function
exec();

}
?>
pete at surfaceeffect dot com
13-Oct-2009 09:49
One fairly important difference between php's abstract functions and, say, Java, is that php does not specify the return type in any way - or indeed whether there has to be one.

<?php public abstract function square($number); ?>

could be implemented by...

<?php
public function square($number) {
   return
$number*$number;
}
?>

or

<?php
public function square($number) {
   print (
$number*$number);
}
?>

So you need to take care that incompatibilities don't arise due to not returning the right kind of value and this is not enforced in any way.
Cheese Doodle
22-Sep-2009 11:13
There isn't really that much of a great hurdle in understanding these things, there really isn't.

If you're defining a new class that is abstract, it means that you can make some non-abstract functions that you can use to define the general underlying behavior of that class along side abstract ones.

In interfaces, you can't do that since functions defined therewithin cannot have a body.

Abstract functions you use for classes that must define more specific behavior when "extending" your class.

So for a crude example - define by your non-abstract functions how that particular object (which may be part of a larger class hierarchy) would store and process it's data in SQL, XML, etc.

Then define abstract functions which allow someone implementing that class to specifically manipulate the data that is to be stored. Then require a format which this data must be returned in, and then in your non-abstract functions call those functions on destruction, in normal runtime, and so on.

Again, non-abstract functions, or even another class could implement the finer points of ensuring that data is in the correct format, and so on, ad infinitum.

It isn't too much of a reach to say that if you used a normal class instead of an abstract class, then there isn't much intrinsic requirement between the two classes.

Assuming that you wanted the functions to use each-others functions and you'd need to use them specifically by name, you'd have to write some code which checked to see -- lamely using function_exists() and other lamery -- if that class has the function you require for interoperability, when you could avoid all possible confusion and headaches by simply using the right tool for the job.

And reading a decent OOP book.
Michael McNally
16-Sep-2009 07:00
This is a case study of how programmers never think alike if I've ever seen one.

The truth must be bare.

1. Interfaces are a set of rules saying "Hey, if you implement me you must include these properties and methods in your class or else a fatal error!"  You don't actually define the values of these properties or the statements of these methods in the interface.

2. Abstract classes are a set of "base" properties and methods that you can extend onto a more specific class.  Though I'm still not sure why creating a normal class with these basic properties and methods would not suffice.
Kiam
01-Aug-2009 07:04
The person - student - employee is the classic example where the interfaces are more appropriate.
It is true that students, and employees are persons, but a person can be both a student, and an employee.

<?php
class Person {
 
// Properties for Person objects.
}

interface
IStudent {
 
// ...
}

interface
IEmployee {
 
// ...
}

class
Student implements IStudent extends Person {
 
// ...
}

class
StudentEmployee implements IStudent, IEmployee extends Person {
 
// ...
}
?>
eeescalona
03-Jun-2008 04:04
here is a real world example of abstract using:

a (abstract) person class
a student and an employee final class, which extends person class.

simple theory is that both student and employee is an extension of the person class.  the difference lies on which table the data is written on, and what other pre processing (ie mandatory field checking, type checking, etc.) needed before writing each of the classes.

codes:

<?php

abstract class person {
   
    abstract protected function
write_info();
   
    public
$LastName;
    public
$FirstName;
    public
$BirthDate;
   
    public function
get_Age($today=NULL){
       
//age computation function
   
}
}

final class
employee extends person{
    public
$EmployeeNumber;
    public
$DateHired;

    public function
write_info(){
        echo
"Writing ". $this->LastName . "'s info to emloyee dbase table";   
       
//ADD unique mandatory checking unique to EMPLOYEE ONLY
        //actual sql codes here
   
}
}

final class
student extends person{
    public
$StudentNumber;
    public
$CourseName;
   
    public function
write_info(){
        echo
"Writing ". $this->LastName . "'s info to student dbase table";
       
//ADD unique mandatory checking unique to STUDENT ONLY
        //actual sql codes here
   
}
}

///----------
$personA = new employee;
$personB = new student;

$personA->FirstName="Joe";
$personA->LastName="Sbody";

$personB->FirstName="Ben";
$personB->LastName="Dover";

$personA->write_info();
?>

OUTPUT:Writing Sbody's info to emloyee dbase table
Anonymous
20-May-2008 07:33
abstract method means you have to implement it in your child classes. You theoretically have two different methods since they have two different argument sets. It sees what you have is not implementing the method, but trying to override it. Which is not the same. Although I am not sure if php has override functionality yet ..
keithjfrank at gmail dot com
13-May-2008 08:19
While building my database class, I came across something I didn't see any documentation on...

abstract class db
{
    abstract protected function prepareSelect();
}

class dbPlugin extends db
{
    /**
     *    Prepare Select
     *    Populates $this->currentQuery with MySQL formatted SELECT query.
     *
     *    @param    string    Fields to retrieve
     *    @param    string    Table from which fields will be selected
     *    @param    string    Optional WHERE restriction
    **/
    protected function prepareSelect( $fields, $table, $where = NULL )
    {
        $this->currentQuery .= "SELECT {$fields} FROM {$this->dbSettings['sqlPrefix']}{$table}";
       
        if ( $where !== NULL )
        {
            $this->currentQuery .= " WHERE {$where}";
        }
    }

}

While executing the script I was greeted with: Fatal error:  Declaration of dbPlugin::prepareSelect() must be compatible with that of db::prepareSelect() in [...]\includes\plugins\dbMySQL.php on line 209

The fix? Adding the same expected variables to the parent abstract method.

abstract class db
{
    abstract protected function prepareSelect( $fields, $table, $where );
}

I am unsure as to whether this is common knowledge or not, but I figured I would share to ease someone else's frustration while figuring out what was going awry. :)
ironiridis at gmail dot com
27-Mar-2008 09:56
Just one more time, in the simplest terms possible:

An Interface is like a protocol. It doesn't designate the behavior of the object; it designates how your code tells that object to act. An interface would be like the English Language: defining an interface defines how your code communicates with any object implementing that interface.

An interface is always an agreement or a promise. When a class says "I implement interface Y", it is saying "I promise to have the same public methods that any object with interface Y has".

On the other hand, an Abstract Class is like a partially built class. It is much like a document with blanks to fill in. It might be using English, but that isn't as important as the fact that some of the document is already written.

An abstract class is the foundation for another object. When a class says "I extend abstract class Y", it is saying "I use some methods or properties already defined in this other class named Y".

So, consider the following PHP:
<?php
class X implements Y { } // this is saying that "X" agrees to speak language "Y" with your code.

class X extends Y { } // this is saying that "X" is going to complete the partial class "Y".
?>

You would have your class implement a particular interface if you were distributing a class to be used by other people. The interface is an agreement to have a specific set of public methods for your class.

You would have your class extend an abstract class if you (or someone else) wrote a class that already had some methods written that you want to use in your new class.

These concepts, while easy to confuse, are specifically different and distinct. For all intents and purposes, if you're the only user of any of your classes, you don't need to implement interfaces.
remi dot alvado at gmail dot com
08-Feb-2008 10:21
I think there is actually an issue in your object model. Indeed, the following code does not work :

<?php
interface Foo {
   public function
myFoo();
}

abstract class
Bar implements Foo {

   public abstract function
myFoo();

   public abstract function
myBar();

   public function
myBar2() {
      echo
"myBar2";
   }
}

class
myImplementation extends Bar {
   public function
myFoo() {
      echo
"Foo";
   }
   public function
myBar() {
      echo
"Bar";
   }
}
?>

Your only chance to make it work is to remove the declaration of abstract method "myFoo" into abstract class "Bar". From my point of view, it is quite strange (PHP seems to consider interface as "special" abstract class (which is not completly wrong)) but it works like that. Took me some time to understand this ;)
nrg1981 at hotmail dot com
28-Jan-2008 02:57
As obvious as this may or may not seem; function properties declared as references in abstract functions must also be declared as references in child classes.

<?php

abstract class A
{
    abstract function
hello(&$ref);
}

class
B extends A
{
    function
hello(&$ref)
    {
       
$ref = 'sausage';
    }
}

$b = new B();
$b->hello($ref);

var_dump($ref);

?>

Otherwise it returns the error:
Declaration of B::hello() must be compatible with that of A::hello()

References are a bit of an odd one in PHP so I thought it worth mentioning here seeing as no-one else has already.
sneakyimp at hotmail dot com
10-Oct-2007 12:05
Ok...the docs are a bit vague when it comes to an abstract class extending another abstract class.  An abstract class that extends another abstract class doesn't need to define the abstract methods from the parent class.  In other words, this causes an error:

<?php
abstract class class1 {
  abstract public function
someFunc();
}
abstract class
class2 extends class1 {
  abstract public function
someFunc();
}
?>

Error: Fatal error: Can't inherit abstract function class1::someFunc() (previously declared abstract in class2) in /home/sneakyimp/public/chump.php on line 7

However this does not:

<?php
abstract class class1 {
  abstract public function
someFunc();
}
abstract class
class2 extends class1 {
}
?>

An abstract class that extends an abstract class can pass the buck to its child classes when it comes to implementing the abstract methods of its parent abstract class.
linus dot martensson at elplan-gm dot se
20-Sep-2007 08:22
This should be a lot more obvious than people make it out to be.

The difference between an interface and an abstract class, is that an interface does not define the behavior of an object.
Rather, it defines how you work with a class.

You use interfaces to decouple the behavior of a class from the accessors and mutators which make up the class.
With an abstract class, you are saying that "Method X should work like this", "Variable Y should be used", an interface could be used to do something completely different.
A well-known usage is that of the proxy.
A proxy is used to moderate access to the real object without modifying the class which describes the object.
Instead, you create a new class, implementing the same interface, adding the new behaviour in the new class.
This could be security checks, accessing a remote object through a TCP/UDP connection, or simply using a light object to avoid creating the heavier one unless it's explicitly necessary depending on the accessed functions.
Either way, the abstract class does not allow this, as it has already decided how the class should work. The interface is much more open-ended in this way and would allow for the same, as it never decides anything about the object implementing it.
pierre at pamdata dot com
01-Aug-2007 07:24
I still don't understand why people want to compare Interfaces and Abstract classes.

They are made for two different purposes in a "development environment".

Interfaces are made for class USERS(the ones who instantiate the class that implements the Interface).
Interfaces can be considered as an agreement between the Class USER and the  Class BUILDER/OWNER.
In other words the class Builder/Owner must implement exactly what is in the Interface.

While Abstract Classes are made for other Class builders who are going to EXTEND a "abstract" parent class.
The abstract class will tell what methods to use without changing it, and what methods you can implement in your Child class.

What ever the OOP language used, it should be the same concept.(Those are pure OOP concepts)

As simple as that.

Please,Don't be confused.Take a look again at:

http://www.php.net/manual/en/language.oop5.abstract.php#75990
eamon at gizzle dot co dot uk Eamon Straughn
20-Jul-2007 11:20
Sometimes I wonder. PHP needs to be pushed to its limits and below everyone fails to understand what an interface is and what abstraction is. So let me make it extremely clear as I have many languages under my belt.

Interfaces are in general WYSIWYG implementations of logic which in PHP are not accessible like in other languages like Java \ ASP.NET where you don't have to access the class itself...however in future I hope PHP does give us this functionality. Interfaces in PHP only define public functions without any basic or core functionality therefore making it lesser a friend to PROs from OOP && OOD backgrounds.

Instead Abstraction in PHP is perfered as this allows your objects a core with the ability to define different levels of access to methods | variables | constants. Although publicly allowing access to variables (to me) | (to official \ senior programmers) defeats the whole idea of OO. Abstraction allows the keywords of final which is very important to me as I can have many child objects of objects and of child objects.

Thus knowing the difference helps with your choosen style but if your really looking to make an application with Abstraction I would always suggest using an Abstract Class instead of Interfaces as Interfaces are limited and provides no functionality and is a waste of bytes on your hard drive.

The below is an example of Abstraction used in an automated system.

<?php
Abstract Class events
{
    protected
$priority;
    protected
$message;
    protected
$environment;
    protected
$syslog;
    protected
$config;
    protected
$global;
    protected
$classes;
    protected
$super;
       
  public function
__construct(array &$config)
    {
       
$this->config = $config;
    }
   
    abstract protected function
writeToDatabase(Environment &$environment);
    abstract protected function
writeToSystem(Environment &$environment);
    abstract protected function
writeToEmail(Environment &$environment);
    abstract protected function
writeToMobile(Environment &$environment);
    abstract public function
execute(&$class, $method, $args);
   
    protected function
environment(Exception &$object) {
       
$this->super =& new Environment($object, $this->config);
       
$this->global = $this->super->env();
       
$this->global = $this->global['environment'];
        return
$this->super;
    }
   
  public function
__destruct()
  {
        unset(
$this);
  }
}
?>
Wes
06-Jul-2007 09:29
a simple solution to write an abstract class with the constructor predefinition

interface MyBaseClassAbstract
{
    public pleaseDefineThisMethod();
}

class MyBaseClass
{
    function __construct()
    {
        if(get_class($this) == __CLASS__)
            throw new Exception("you can't instantiate this class");
        else
        {
            //common constructor
        }
    }
}

class MyClass extends MyBaseClass implements MyBaseClassAbstract
{
    function pleaseDefineThisMethod()
    {
        echo "hello";
    }
}

$test = new MyClass();
$test = new MyBaseClass(); // error!
pierre at pamdata dot com
26-Jun-2007 01:25
I love examples.
This example will let you see that an Interface and an Astract Class are two different entities.

Just go and read the Object Interface section at :
http://www.php.net/manual/en/language.oop5.interfaces.php

and look at this example

<?php
/*
* A Very simple example to understand why we should use ABSRACT CLASSES.
* This abstract class contains  2 methods : 1 abstract and 1 common methods.
*
*/
abstract class Shape
{
   
# Let's assume a shape will always have a base and a height
   
protected  $base;
    protected
$height;
   
   
#This function can be the same for both classes  'Triangle' and 'Rectangle'
   
public function getValue($base,$height)
    {
       
$this->base = $base;
       
$this->height = $height;
    }
   
   
# This might be different for each class of shape, because each Surface is calculated by a different formula ( St = b*h/2  and  Sr = b*h)
   
abstract public function surface();
}

class
Triangle extends Shape
{
   
# s = b*h/2
   
public function surface(){
        return
round((($this->base)*($this->height)/2),2);
    }
}

class
Rectangle extends Shape
{
   
# s = b*h
   
public function surface(){
        return
round((($this->base)*($this->height)),2);
    }
}

$r = new Rectangle();
$r->getValue(15,3);
echo
$r->surface() ."\n";   # echo 45

$t = new Triangle();
$t->getValue(15,3);
echo
$t->surface() ."\n";   # echo 22.5

?>
joebert
24-Jun-2007 11:09
I don't agree with jfkallens' last comparison between Abstract Classes & Object Interfaces completely.

In an Abstract Class, you can define how some methods work, where as in an Object Interface you can not.

An Object Interface is essentually nothing but a list of function names that a class must define if the class implements that interface.

An Abstract Class is essentually a prototype which hints towards what extending classes should be doing.
An Abstract Class can also be thought of as a Base Class that provides some basic functionality, & also defines a built-in Object Interface that all extending classes will implement.

So, an Object Interface is really a built-in part of an Abstract Class.
jfkallen at hotmail dot com
11-Jun-2007 03:25
A couiple of years ago I raised the question on this website as to what the difference between an interface and an abstract class is.  At some point I learned how to define the words for myself since then - and now all is clear :)

An interface allows you to define what is conceptually the same thing as an abstract class except that all methods are public.  That makes sense as an "interface" represents how an app or environment interacts with the object - normally via public methods.
david at mr-t dot nl
25-Jul-2006 03:27
It took me a while to figure this out and i couldn't find it easily in the documentation anywhere.

If you want to override a method from a base class and want to call the base class in the method, then you have to use the parent::function() syntax, even though the method isn't static. There is no $base variable in php that i know of.

Expamle:
<?php
public abstract class BasePerson() {
 
/*
   * alot of code..
   */
 
public function getName() {
    return
$this->name;
  }
}

public class
Person() extends BasePerson {
 
/*
   * alot of code..
   */
  // override of base getName()..
 
public function getName() {
   
// you would expect $base->getName() instead of parrent::getName()...
   
return htmlspecialchars(parent::getName());
  }
}
?>

Hope this helps!
James
16-May-2006 05:10
A nice tutorial on PHP5's abstract classes and interfaces:

Working with php5 class types abstract classes and interfaces.

http://www.phpfive.net/article4.htm
gsteren at gmail dot com
06-Mar-2006 01:48
Abstract classes allow the declaration of protected abstract methods, which cannot be emulated with the use of an interface and a concrete superclass.

Even private abstract methods can be declared, although I fail to see the use in them, as subclasses will not see them anyway.
rasto_klc (at) yahoo (dot) obvious
28-Dec-2005 09:27
Variable-length argument lists in abstract methods will generate fatal error if derived. Here is an simple example:

<?php
// common wrap for all validators is forcing uniform interface
abstract class ValidatorWrap {

   
// just example why variable-length arguments are needed
   
public function __construct()
    {
        if (
func_num_args() > 0) {
           
$arg_list = func_get_args();
           
call_user_func_array(array(&$this, 'setupValidator'), $arg_list);
        } else {
           
$this->setupValidator();
        }
       
// continue with construction
   
}

   
// amount of arguments is specific to validator implementation
   
abstract public function setupValidator();

   
// known interface
   
abstract public function validate($value);
}

class
Validator1 extends ValidatorWrap {

    protected
$pattern = '';

   
// this will generate PHP Fatal error because $pattern is not expected
   
public function setupValidator($pattern)
    {
       
$this->pattern = $pattern;
    }

   
// this will do OK
   
public function validate($value)
    {
        return
preg_match($this->pattern, $value);
    }
}

// make numeric validator
$validator = new Validator1('/^\d+$/');
echo (int)
$validator->validate($_REQUEST['digits']);
?>

I need it to work so I just redefine troublemaking function as follows:

<?php
   
public function setupValidator() { }
?>

This will give me functionality I need and generates only PHP Strict Standards warning.
turgut85 at hotmail dot com
02-Dec-2005 05:38
<?php

// Design Pattern ABSTRACT FACTORY  implementation //

abstract class AbstractFactory {
    public abstract function
CreateProductA();  // return data type is AbstractProductA
   
public abstract function CreateProductB();  // return data type is AbstractProductB
}

// Abstract factory #1 //
class ConcreteFactory1 extends AbstractFactory {

    public function
CreateProductA() { // return data type is AbstractProductA
       
return new ProductA1();
    }

    public function
CreateProductB() { // return data type is AbstractProductB
       
return new ProductB1();
    }
}

// Abstract factory #2 //
class ConcreteFactory2 extends AbstractFactory {

    public function
CreateProductA() { // return data type is AbstractProductA //
       
return new ProductA2();
    }

    public function
CreateProductB() { // return data type is AbstractProductB //
       
return new ProductB2();
    }
}

// "AbstractProductA" //
abstract class AbstractProductA {
}

// "AbstractProductB" //
abstract class AbstractProductB {
    public abstract function
Interact($a); // return type is void // // input type is  AbstractProductA
}

// "ProductA1" //
class ProductA1 extends  AbstractProductA {
}

// "ProductB1" //
class ProductB1 extends  AbstractProductB {

    public function
Interact($a) {
        echo
__CLASS__." interacts with ".__METHOD__."\n";
       
var_dump($a);
    }
}

// "ProductA2"
class ProductA2 extends AbstractProductA {
}

// "ProductB2"
class ProductB2 extends AbstractProductB {
    public function
Interact($a) {
        echo
__CLASS__." interacts with ".__METHOD__."\n";
       
var_dump($a);
    }
}

class
Client {

    private 
$AbstractProductA;                            // type AbstractProductA;
   
private  $AbstractProductB;                            // type AbstractProductB;

    // Constructor
   
public function __construct($factory) {
       
$this->AbstractProductB = $factory->CreateProductB();
       
$this->AbstractProductA = $factory->CreateProductA();
    }

    public function
Run() {
       
$this->AbstractProductB->Interact($this->AbstractProductA);
    }
}

// Abstract factory #1
$factory1 = new ConcreteFactory1();
$c1 = new Client($factory1);
$c1->Run();

// Abstract factory #2
$factory2 = new ConcreteFactory2();
$c2 = new Client($factory2);
$c2->Run();

// TURGUT Z. YESILYURT, MS
// Software Developer
// NewJersey, USA

?>
Output::

ProductB1 interacts with ProductB1::Interact
object(ProductA1)#4 (0) {
}
ProductB2 interacts with ProductB2::Interact
object(ProductA2)#8 (0) {
}
mail dot phatlip at gmail dot com
07-Nov-2005 05:04
just RE: ramonzamora at gmail dot com

Abstraction is 'stricter' than inheritance+implementation as it contains 'rules' about the visibility of the methods that are inherited, as well as the fact that it saves needing two classes to get a job done.

The fact you cannot instantiate an abstract class can be benificial also.
ramonzamora at gmail dot com
27-Aug-2005 10:46
so abstract clases are the same than inheritance+interfaces??

<?php

//using inheritance+interfaces

interface callA{
    protected function
callA();
}

class
callB{
    protected
$b;
    protected function
callB(){
        return
$this->b;
    }
}

class
caller extends callB implements callA{
    protected
$a;
    public function
__construct($a,$b){
       
$this->a=$a;
       
$this->b=$b;
    }
    protected function
callA(){
        return
$this->a;
    }
 
    public function
callAB(){
        return
$this->callA().$this->callB();
    }
}

$caller=new caller('a','b');
$caller->callAB();

//using abstract class

abstract class callAB{
    abstract protected function
callA();
    protected
$b;
    protected function
callB(){
        return
$this->b;
    }
}

class
caller extends callAB{
    protected
$a;
    public function
__construct($a,$b){
       
$this->a=$a;
       
$this->b=$b;
    }
    protected function
callA(){
        return
$this->a;
    }
    public function
callAB(){
        return
$this->callA().$this->callB();
    }
}

$caller=new caller('a','b');
$caller->callAB();
?>

the only difference i see is that using inheritance+interfaces you can instantiate the parent but using abstract classes you can't

Interfaces> <Static Schlüsselwort
Last updated: Fri, 30 Oct 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites