object oriented Interfaces in PHP

Like other object oriented programming languages, we can define Interfaces in php as well.

Here is the code to define and use interfaces in php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

</head>

<body>
<?php
interface MyInterface
{
  
}

class MyClass implements MyInterface
{
  
}

$a = new MyClass;
$b = new MyClass;
$c = "MyClass";
$d = "NotMyClass";

var_dump($a instanceof $b);
var_dump($a instanceof $c);
var_dump($a instanceof $d);
?>
</body>
</html>

 

Add a Comment

Your email address will not be published. Required fields are marked *