Interface / type query in PHP

Time:2021-6-24

In PHP language, we can judge whether a variable belongs to an instance of a specified class or interface through the type operator instanceof

<?php
interface I {
     public  function hello();
}

class A implements  I {
     public function hello()
     {
         // TODO: Implement hello() method.
          print ("Hello from A\n");
     }
}

class B extends  A {
     public function  greeter (){
         print("Hello from B\n");
     }
}
$a=new A;
$b=new B;
var_dump($b  instanceof B);
var_dump($b instanceof A);
var_dump($b instanceof I);

Recommended Today

C # regular implementation of UBB parsing class code

The parsed code can pass XHTML   one   Strict verification;It includes title, link, font, alignment, picture, reference, list and other functions  Ubb.ReadMe.htm UBB code description title [H1] title I [/ H1] Title I [H2] Title II [/ H2] Title II [H1] Title III [/ H1] Title III [H4] Title IV [/ H4] Title IV […]