//php 5 提供了關鍵字 instanceof 用以判斷一個對象是否是某個類或接口的實例
//instanceof 相當于php 5 之前的版本的 is_a() 函數
interface I{};
class A implements I{};
class B extends A{};
$thing = new A();
if($thing instanceof A){
echo "thing is the instance of A /n";
}
if($thing instanceof B){
echo "thing is also the instance of B /n";
}
else{
echo "thing is not the instance of B /n";
}
if($thing instanceof I){
echo "thing is also the instance of I /n";
}
else{
echo "thing is not the instance of I /n";
}
$anotherthing = new B();
if($anotherthing instanceof B){
echo("anotherthing is the instance of B /n");
}
if($anothering instanceof A){
echo("anotherthing is the instance of A /n");
}
else{
echo("anotherthing is not the instance of A /n");
}
if($anotherthing instanceof I){
echo("anotherthing is the isntance of I /n");
}
/* $inter = new I(); if($inter instanceof I){ echo("inter is the instanceof I /n"); } */ ?>