what is interface in php? how it is use?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why php is used in html?

531


What is php oops concepts?

528


Is null in php?

536


What is php oop?

519


Is php an api?

537






Which function would you use to read a line of data from a file in php?

564


Is server side a session?

500


Why does sql injection happen?

577


What is escaping to php?

544


How to create reusable code in php?

552


How to remove values saved in the current session?

539


What does it mean when it says the csrf token is invalid?

500


Is php a middleware?

521


Can I learn laravel without php?

579


What is a string in php?

557