what is interface in php? how it is use?

Answers were Sorted based on User's Feedback



what is interface in php? how it is use?..

Answer / jadhav yeshwanth

An Interface is like a template similar to abstract class
with a difference where it uses only abstract methods.

In simple words, an interface is like a class using
interface keyword and contains only function
declarations(function with no body).

An Interface should be implemented in the class and all the
methods or functions should be overwridden in this class.

for eg:

interface InterfaceName{
function fun1();
function fun2(a,b);
}

class ClassName implements InterfaceName{
fuction fun1(){
function implementation.......
}
fuction fun2(a,b){
function implementation.......
}
}

Is This Answer Correct ?    125 Yes 19 No

what is interface in php? how it is use?..

Answer / asish kumar khuntia(mithu)

Interface is a object oriented concept,
It is the place where we can define the function.
When a class use that interface in that class the total
function body part will describe.
after that we can call that function in other class and we
are get result.

Is This Answer Correct ?    79 Yes 26 No

what is interface in php? how it is use?..

Answer / thirupathi rao

Interface is a prototype of method body.
when ever we want to develop the application by third party
vendor people, at that time we have to provide only interface.
why because the people gives the implementation in their own
way so we have to provide the interface.

Is This Answer Correct ?    30 Yes 8 No

what is interface in php? how it is use?..

Answer / sanjeev kumar

Interface: Since we all knows that PHP does not support the
multiple inheritance. But don't worry we have an excellent
idea to do the multiple inheritance in php is Interface.
Interface is just like a class using interface keyword and
contains only function declarations(function with no body).
function is defined in the classes where you call it.

Ex:-

interface FirstInterfName{
function Add();
function Sub(10,5);
}

interface SecondInterfName{
function glbfunc1();
function glbfunc2();
}


class ClassName implements FirstInterfName,SecondInterfName
{
fuction Add()
{
$a = 5;
$a = $a + 1;
echo $a;
}

fuction Sub($a,$b)
{
$c = $a -$b;

echo $c;
}

function glbfunc1()
{
Implements here method...............
}

function glbfunc2()
{
Implements here method...............
}

}

Is This Answer Correct ?    24 Yes 7 No

what is interface in php? how it is use?..

Answer / nur nahid hasan

Interface: Since we all knows that PHP does not support the
multiple inheritance. But don't worry we have an excellent
idea to do the multiple inheritance in php is Interface.
Interface is just like a class using interface keyword and
contains only function declarations(function with no body).
function is defined in the classes where you call it.

Ex:-

interface FirstInterfName{
function Add();
function Sub(10,5);
}

interface SecondInterfName{
function glbfunc1();
function glbfunc2();
}


class ClassName implements FirstInterfName,SecondInterfName
{
fuction Add()
{
$a = 5;
$a = $a + 1;
echo $a;
}

fuction Sub($a,$b)
{
$c = $a -$b;

echo $c;
}

function glbfunc1()
{
Implements here method...............
}

function glbfunc2()
{
Implements here method...............
}

}

Is This Answer Correct ?    19 Yes 6 No

what is interface in php? how it is use?..

Answer / raju

Interface gets useful when you need to extend a class from
more than one parent class since class can not do this.

Why would you want to implement just a single interface on a
class. After all, a class already has everything that an
interface has.

Is This Answer Correct ?    14 Yes 8 No

what is interface in php? how it is use?..

Answer / sivannarayana

interface = multiple inheritance

means:
An interface is a named collection of method definitions, without implementation.

example:
interface interfaceName{
public function func1();
public function func2();
}

//we will use this interface as
class ClassName implements interfaceName
{
//note all interface func's must implement here
}

Is This Answer Correct ?    5 Yes 0 No

what is interface in php? how it is use?..

Answer / karthi

interface =multiple inheritance

means:
An multiple inheritance is not supported in php that time we
using interface. It is implements two baseclasses but class
extends only one class.

Is This Answer Correct ?    4 Yes 1 No

what is interface in php? how it is use?..

Answer / neakdek

Why you can :

interface FirstInterfName{
function Add();
function Sub(10,5); // this line can u pass 10,5 like this
}

Is This Answer Correct ?    4 Yes 8 No

what is interface in php? how it is use?..

Answer / johan

in english? lol

Is This Answer Correct ?    13 Yes 60 No

Post New Answer

More PHP Interview Questions

Echo is used to Display message on screen. Which is used with echo to not output the trailing newline?

0 Answers  


What does $_server means?

0 Answers  


Explain how we can get the number of elements in an array?

0 Answers  


What is data structure in php?

0 Answers  


What is a role of a designer in web development. Till what level the designer will do his work. Does he gives the complete html file or the tpl file or he should also include the smarty tag in the tpl file.

1 Answers  






code to see the priview of the image which is being uploaded (after browising the image... just click priview ... how it will be visible...before uploading)

0 Answers   Satyam,


What is the main difference between php 4 and php 5?

0 Answers  


How to delete an element from an array?

0 Answers  


What is meant by PEAR in PHP?

0 Answers  


Hi, My Name is Ajay Jha. What My Question is I am Percuing in Bca. It's My 5th Semester. I Want To Make My Carrear as a web designer that's Why i wants to do Php, Is it right Desision for Me ?

1 Answers  


What is the difference between explode () and split () functions in php?

0 Answers  


How to insert a line break in php string?

0 Answers  


Categories