Share on Google+Share on Google+

PHP Interface Class


In this tutorial you will study about interface of PHP, how to declare and implement an interface, what points should be kept in mind when we declare an interface etc. Interface is also a class but it has few constraints unlike any other ordinary concrete class and it supports the multiple inheritance.

PHP Interface Class:

PHP does not support multiple inheritance directly, to implement this we need Interface. It is much similar to Interface of Java.

In PHP, signature of the method are declared in the Interface body, and the body part of the method is implemented in derived class. Variables are declared as constant and it can not be changed in the child classes.

We use implement keyword to extend this kind of class, at the same time we can implement more than one interface and one interface can be implemented by another interface.

All methods declared in an interface must be public and the variables should be constant.

This is mandatory that we must declare the body part of the method in the derived class otherwise an error message will be generated.



interface Inter{

const a="This is constant value";

public function disp(); }

class A implements Inter{

function show(){

echo self::a."<br/>";}

public function disp(){

echo "Inside the disp function";}}

$a=new A();





This is constant value
Inside the disp function




Posted on: February 20, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null